9

I have a reference to System.Data in my windows service project. I keep getting the Exception :

Could not load file or assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

I attach the FusionLog to my code and found out the following. For System.Data only visual studio is looking here:

Assembly manager loaded from: C:\windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll

And it should be looking here (all the other assemblies are but System.Data)

Assembly manager loaded from: C:\windows\Microsoft.NET\Framework\v4.0.30319\clr.dll

How can I do point my System.Data file to look in the right place?

My guess is Microsoft Commerce Server dlls are referenceing the 2.0 folder maybe.

svick
  • 236,525
  • 50
  • 385
  • 514
Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152

3 Answers3

5

Add this to app.config..

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>

If you need old versions of dlls to be loaded in a windows service you must add this. For web services iis automatically takes care of it, but not for windows service.

Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152
  • I have the same problem with my .Net 3.5 project, even had above useLegacyV2RuntimeActivationPolicy added. But I can still observe "System.Data not found" exception in Visual Studio output window as first chance exception when debug run. However, except for this, my application runs OK. – neolei Feb 14 '20 at 04:44
2

Make sure your project is set to .Net Framework 4. If that doesn't do it, set it to full profile (not just Client)

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
2

If you select the referenced assembly in the solution explorer, verify that the runtime version is correct (see image below). You can remove the reference and re-add it to fix it if necessary.

Also, if you are using an app.config, make sure it is targeting the correct runtime version.

enter image description here

BryanJ
  • 8,485
  • 1
  • 42
  • 61
  • I verified all System.Data dlls in all projects in the solution have the 4.0 runtime version and the app config is targeting 4.0 – Nick LaMarca May 21 '12 at 14:53