2

I have been facing this weird issue with my WCF service which is already Deployed. It has been set to automatic restart in case of errors.

I have been observing my service is getting stopped randomly. And I don't get any log of the same.

It has been giving me below Exception

Service cannot be started. System.ArgumentNullException: Value cannot be null.
Parameter name: path
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at CommonNameSpace.Generator.Utility.ExceptionLog(Exception ex) in C:\Users\downstreamdev01\source\repos\Project\MyService\Myservice.Solution\Myservice.BusinessLogic\Utility.cs:line 22
   at MyServiceNamespace.MyService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

Here is the code of method it is pointing to.

public static void ExceptionLog(Exception ex)
        {
            string gh = GetConfigurationValue("ErrorLog");
            StreamWriter swFileLog = new StreamWriter(GetConfigurationValue("ErrorLog"), append: true);
            StringBuilder sbErrorLog = new StringBuilder();

            sbErrorLog.AppendLine("******* ERROR Log  -  START **********");
            sbErrorLog.AppendLine("[Date Time]: " + DateTime.Now.ToString());
            sbErrorLog.AppendLine("[ex.Source]: " + Convert.ToString(ex.Source));
            sbErrorLog.AppendLine("[ex.Message]: " + Convert.ToString(ex.Message));
            sbErrorLog.AppendLine("[ex.InnerException]: " + Convert.ToString(ex.InnerException));
            sbErrorLog.AppendLine("########### StackTrace - START ###########");
            sbErrorLog.AppendLine(" ");
            sbErrorLog.AppendLine("[ex.StackTrace]: " + Convert.ToString(ex.StackTrace));
            sbErrorLog.AppendLine("[ex.Target Site]: " + Convert.ToString(ex.TargetSite));
            sbErrorLog.AppendLine("########### StackTrace - END ###########");
            sbErrorLog.AppendLine(" ");
            sbErrorLog.AppendLine("******* ERROR Log  -  END **********");
            swFileLog.WriteLine(sbErrorLog.ToString());
            swFileLog.Close();
        }

I can not understand what is happening here. When I try to restart it, It keeps showing the Could not start Windows Service, Error 1064 error. But I then rebuild the windows service project and try to start it again and it gets started.

Can Anyone tell what can be the issue here? or possible way which can prevent such things?

Maulik Modi
  • 1,205
  • 12
  • 22
  • I think it's pretty clear that `GetConfigurationValue("ErrorLog")` is returning null. Since the error goes away after you rebuild and redeploy I would guess that some build artifact is required for `GetConfigurationValue` to return a value and perhaps that build artifact is being deleted or modified somehow? But that is a total shot in the dark given the lack of details. One thing I would try is to diff the existing deployed directory and the build output before you re-deploy (if you're running from your build directory I would either stop doing that or make a copy of the directory). – Paul Wheeler Dec 11 '19 at 21:15

0 Answers0