System.Data Assembly Not found
Asked Answered
T

3

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.

Tartu answered 17/5, 2012 at 19:4 Comment(0)
T
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.

Tartu answered 22/5, 2012 at 13:52 Comment(1)
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.Instep
P
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)

Porter answered 17/5, 2012 at 19:8 Comment(10)
@NickLaMarca Is the full framework installed on the client then?Blepharitis
Sanity check - can you find the file C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll ?Stronghold
The folder v4.0.30319 is installed on my machineTartu
Yes I see System.Data.dll here: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0Tartu
Do you have <startup><supportedRuntime version="v2.0.50727" /></startup> in your web.config?Stronghold
I have this in my app.config <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup>Tartu
Just curious - are you passing DataSets around through you web service?Stronghold
this is a windows service and yes I am calling datasets then mapping them to an objectTartu
That could be your problem, if your client is 2.0 and your server 4.0Stronghold
4.0 is installed on server and clientTartu
A
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

Arlin answered 21/5, 2012 at 14:52 Comment(1)
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.0Tartu

© 2022 - 2024 — McMap. All rights reserved.