3
votes

I today tried to use windows 8 and visual studio 2010 for our big project. I am getting an error from some projects stating the assembly System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a cannot be resolve "because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through ReflectionOnlyAssemblyResolve event." The error appears during compilation.

We do not directly reference this assembly in our project. It seems that maybe the Microsoft Enterprise Library (Version 5.0.414) uses this assembly. But why it is not there? I thought it is part of the .NET Framework.

The TargetFramework of the project is .NET 4.0

What can I do to solve this problem?

2
System.Management is definitely part of the .NET Framework. Does the error go away if you add a reference to it in whichever project is giving the error message?Malice
Can you remove it, and try and re-add it? It may take a new version, but let us know if that works.Kevin Anderson

2 Answers

2
votes

This is no doubt a problem induced by Assembly.ReflectionOnlyLoad() not applying binding policy. Which prevents the 2.0.0.0 version of System.Management.dll getting mapped to the 4.0.0.0 version.

You can try hacking your own AppDomain.ReflectionOnlyAssemblyResolve event handler but that's fugly. You'd better take the shortcut to this problem, you will soon anyway. Go into Control Panel, Program and Features, Turn Windows features on or off. Tick the ".NET Framework 3.5" option, OK and let it trundle for a while.

0
votes

On my Win8 / VS 2012 machine with a project that targets .NET FX 4, I am only being offered System.Management v4.0.0.0:

System.Management version on Windows 8

I am guessing that your project was originally build for .NET 2/3/3.5, hence the reference to System.Management v2.0.0.

I am also guessing that your code uses some form of lazy-loading and/or Dependency-Injection/Inversion-Of-Control container (e.g. Ninject / Windsor / Autofac / Unity / StructureMap / etc.) and that you have a hard-coded string somewhere in your source that contains the reference to the v2 library?

If so, you'll need to update the reference to System.Management v4.0.0.0 when building for .NET 4.0+.