none
.Net 1.1 Windows service application wouldn't start on certain Windows NT SP6a server RRS feed

  • Question

  • I have a .Net 1.1 Windows service application that wouldn't start on certain Windows NT SP6a server. The server is running .Net 1.1 SP1. The message is see in the event log is
    TestService.exe Common Language Runtime Debugging Services
                  Application has generated an exception that could not be handled.
                  Process ID=0x14 (1300), Thread Id=0xe8(232)


    I have several Windows NT SP6a servers that works just fine. Only a few Windows NT SP6a servers are exhibiting this problem. It is not happening in our test servers. Being that the problem only occurs on production servers I was able to modify the registry to start the TestService.exe with cordbg but I don't any information out of this that seems to be of any help.

    Any pointers would be really appreciated
    SK
    Tuesday, January 12, 2010 6:57 PM

All replies

  • Wow, I didn't realize that .NET 1.1 even supported NT 4 until I looked at the requirements for it...

    Regardless, the typical way to troubleshoot is the same even if you are using later versions of .NET and Windows.  By default, the unhandled error logging is poor, as you have seen.  Modify your code so that very early on (such as first thing in your OnStart method), you attach a handler to the System.AppDomain.UnhandledException event.  In that handler, write e.ExceptionObject.ToString(), which is the exception stack trace, somewhere convenient such as the event log or a file.
    Wednesday, January 13, 2010 12:31 AM
  • Thanks for the suggestion but it didn't help. As soon as I click start on the service control panel,  I get the following error in the event log almost instanteneously,


    "The description for Event ID ( 0 ) in Source ( .NET Runtime ) could not be found. It contains the following insertion string(s): .NET Runtime version 1.1.4322.2032- testsimpleservice.exe - Common Language Runtime Debugging Services: Application has generated an exception that could not be handled.

    Process id=0xd2 (210), Thread id=0x59 (89).

    Click OK to terminate the application.
    Click CANCEL to debug the application.."

    I also tried to use the technique suggested at http://support.microsoft.com/kb/824344 to debug windows services and here's what cordbg.exe has to report,


    Warning: couldn't load symbols for c:\winnt\microsoft.net\framework\v1.1.4322\ms
    corlib.dll
    [thread 0xab] Thread created.
    Unable to  determine existence of prolog, if any
    [thread 0xda] Thread created.
    [thread 0xab] Unhandled exception generated: (0x00d00010) <System.Security.Polic
    y.PolicyException>
      _className=<null>
      _exceptionMethod=<null>
      _exceptionMethodString=<null>
      _message=(0x00cfb030) "Execution permission cannot be acquired."
      _innerException=<null>
      _helpURL=<null>
      _stackTrace=<null>
      _stackTraceString=<null>
      _remoteStackTraceString=<null>
      _remoteStackIndex=0x00000000
      _HResult=0x80131418
      _source=<null>
      _xptrs=0x00000000
      _xcode=0xe0434f4d


    So I thought this was something related to security that's not set correctly. I ran, caspo -all -reset and it didn't help either.


    Here's what my code looks like, It is a test service that I created to diagnose this issue. The service is set to run under the System Account. I have also tried to run the service using an Admin account and that didn't help either. I even tried using Fusion Log viewer to check for Assembly loading issue and I don't see any problems there as well. The only reason why I am testing for the command line argument in my code is to make sure that the exe can run without any issues. When I run the exe standalone it runs and logs the message indicated below which tells me that there's something wrong only with the service side of things,

    public class TestService : System.ServiceProcess.ServiceBase
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public TestService()
            {
                // This call is required by the Windows.Forms Component Designer.
                InitializeComponent();

                // TODO: Add any initialization after the InitComponent call
            }

            // The main entry point for the process
            static void Main(string[] args)
            {
                System.AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
                try
                {
                    if (args.Length > 0)
                    {
                        System.Diagnostics.EventLog.WriteEntry("TestService","console start",EventLogEntryType.Information);
                    }
                    else
                    {
                       
                        System.Diagnostics.EventLog.WriteEntry("TestService","In start",EventLogEntryType.Information);
                        System.ServiceProcess.ServiceBase[] ServicesToRun;
       
                        // More than one user Service may run within the same process. To add
                        // another service to this process, change the following line to
                        // create a second service object. For example,
                        //
                        //   ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
                        //
                        ServicesToRun = new System.ServiceProcess.ServiceBase[] { new TestService() };

                        System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                    }
                }
                catch(Exception e)
                {
                    System.Diagnostics.EventLog.WriteEntry("TestService",e.Message,EventLogEntryType.Error);
                }
            }

            static void MyHandler(object sender, UnhandledExceptionEventArgs args)
            {
                Exception e = (Exception) args.ExceptionObject;
                System.Diagnostics.EventLog.WriteEntry("TestService",e.ToString(),EventLogEntryType.Error);
            }


            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                //
                // TestService
                //
                this.ServiceName = "TestService";

            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                if( disposing )
                {
                    if (components != null)
                    {
                        components.Dispose();
                    }
                }
                base.Dispose( disposing );
            }

            /// <summary>
            /// Set things in motion so your service can do its work.
            /// </summary>
            protected override void OnStart(string[] args)
            {
                try
                {
                    System.Diagnostics.EventLog.WriteEntry("TestService","TestService started",EventLogEntryType.Information);
               
                }
                catch(Exception e)
                {
                    System.Diagnostics.EventLog.WriteEntry("TestService",e.Message,EventLogEntryType.Error);
                }
            }
     
            /// <summary>
            /// Stop this service.
            /// </summary>
            protected override void OnStop()
            {
                try
                {
                    System.Diagnostics.EventLog.WriteEntry("TestService","TestService stopped",EventLogEntryType.Information);
                }
                catch(Exception e)
                {
                    System.Diagnostics.EventLog.WriteEntry("TestService",e.Message,EventLogEntryType.Error);
                }
            }
        }

    SK
    Wednesday, January 13, 2010 2:27 PM
  • Is the service .exe installed locally and accessed through a local drive letter such as c:\?

    Running off of a network requires additional security configuration (this has been improved in .NET 3.5 SP1).
    Thursday, January 14, 2010 12:07 AM
  • Yes, the service has been installed locally and accessed from the C: drive
    Another improvement yesterday - I was messing with the .Net 1.1 Run Time configuration settings and as soon as I set the Run Time policy - Machine - Code Groups - All Code level to Full Trust I was able to start the Service. Ideally only the service should belong to Machine - Code Groups -All Code - My_Computer_Zone however I wasn't able to get it to work.
    So anyway, now the new problem, I am not able to read any configuration setting from the App.Config file,
    The following code doesn't log anything,

    string[] keys = System.Configuration.ConfigurationSettings.AppSettings.AllKeys;
                foreach(string key in keys)
                {
                    System.Diagnostics.EventLog.WriteEntry("Test",
                        "key: " + key
                        ,EventLogEntryType.Information);
                }

    My App.Config looks like this,
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
        <add key="AMax" value="10240"/>
    </appSettings>
    </configuration>

    What a pain this has become. I have to be to able to figure this out as I have too many NT systems to mention that have this problem. Please don't ask why we are still on the NT platform :).

    SK
    Thursday, January 14, 2010 1:54 PM