2

I have a unique case here .

After lots of trials and enough of googling , i am yet not able to resolve this problem.

I have an set of libraries (third party) with runtime version 'v2.0.50727', which i have to use within my WINDOWS SERVICE application ( here is the key 'Windows Service') , which requires .Net v4.0 (v4.0.30319).

I have successfully resolved the Mixed Mode Assembly Error described all over the places.

One of the richest source of solution here :

What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?

The service after installation , does not get started. (Throws the generic timeout exception.)

The MyWindowsService service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

Details in Event Viewer (under windows logs > Application ) specifies 2 sources

  1. .Net Runtime ( details are as follows )

    Application: MyWindowsService.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Configuration.ConfigurationErrorsException Stack: at System.Configuration.ClientConfigurationSystem.EnsureInit(System.String) at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(System.String) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String) at System.Configuration.ConfigurationManager.get_AppSettings() at MyWindowsService..ctor() at MyWindowsService.Program.Main()

    1. Application Error : ( details as follows )

    Faulting application name: MyWindowsService.exe, version: 1.0.0.0, time stamp: 0x53da4547 Faulting module name: KERNELBASE.dll, version: 6.1.7601.18409, time stamp: 0x53159a86 Exception code: 0xe0434352 Fault offset: 0x0000c42d Faulting process id: 0x3814 Faulting application start time: 0x01cfacc646c337dc Faulting application path: c:\Src\bin\MyWindowsService.exe Faulting module path: C:\Windows\syswow64\KERNELBASE.dll Report Id: 8d72e05a-18b9-11e4-a80e-689423ef1889

Important thing here is , if I remove this configurations from app.config - the service starts properly ( obviously breaks at runtime - coz of mixed mode assemblies), whereas keeping it in the config doesn't let it start.

Please guide me on this. Any help would be much appreciated.

P.S: 1. I have tried all the suggestions specified in the stackoverflow link above so far.

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/> </startup>
  1. Using VS 2012 , .Net Framework 4.0 , windows 7
Community
  • 1
  • 1
B Bhatnagar
  • 1,706
  • 4
  • 22
  • 35
  • It is very doubtful that the exception that crashes your program has anything to do with the `` element. It is unhappy about your application settings, without a decent exception message that says why. Subscribe the AppDomain.CurrentDomain.UnhandledException event in your Main() method so you can get a better report. Looks like you are already doing this, it needs work. – Hans Passant Jul 31 '14 at 16:49
  • @HansPassant: i tried your suggestion , but nope could get anything better. – B Bhatnagar Aug 01 '14 at 11:17

1 Answers1

0

One option to determine why your service is not starting is to connect a debugger to the service.

Since debugging a service requires:

  1. starting the service from the Service Control Manager
  2. use the Debug "Attach to Process" option in VS

Since you want to connect to the OnStart method you will need to add a Thread.Sleep(5000); to give yourself 5 seconds to connect the debugger to the service after starting the service from the Service Control Manager. Set a breakpoint just after the sleep statement.

Given that you are .NET run time error you may never get to the breakpoing since it appears to be trouble with loading.

Did you try creating a simple application that uses the same third party library to verify the correct setup of the app.config file?

Try using the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
  <supportedRuntime version="v2.0.50727" />
 </startup>
</configuration>

I found this info here

Community
  • 1
  • 1
Chad Dienhart
  • 5,024
  • 3
  • 23
  • 30
  • I tried debugging the service , bt wasn't able to do so ,the service time out happens anyway ( even though i made the thread sleep ). And Yes , I did try invoking the same service method from a simple application and it runs fine with the config entries specified. Also I have tried many such ... which works fine - resolves the mixed mode error. But here the service doesn't start , with this entry specified in app.config. Thanx for your help though. – B Bhatnagar Aug 01 '14 at 07:16