Missing System.Windows
I have a rather large solution with some Silverlight and WPF projects inside it, as well as some class libraries and other things.
One of the project is a class library that references a SilverLight application which references System.Windows
But at runtime, I get the error:
{"Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=n开发者_如何学Ceutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.":"System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"}
I looked in the GAC (C:\Windows\assembly
) and couldnt see it in there...
Whats happening here?
The reference is to: c:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll
which DOES exist.
Sounds to me like your WPF app is loading a class library that references a Silverlight assembly. That cannot work, cats and dogs. If an assembly is referenced by both a WPF and a Silverlight app then it has to be compiled twice with different framework assembly references. That takes two projects. Keeping the WPF and the Silverlight stuff separate in different solutions is the best way to keep out of trouble.
I've seen similar errors in two cases that might apply here:
When an assembly I reference required an assemble I have not referenced . . . in this case that would mean System.Windows is using something else you need to add a reference too.
The more interesting case is when VS2010 auto selected ".Net Framework 4 Client Profile" for me when I actually needed ".Net Framework 4" (no "client profile"). Select the project properties and see what your setting is.
Frank
Per you request additional instructions:
Open Solution in VS2010, right click the project in question (not the solution line) and select "properties" from the bottom. In the resulting GUI, select the "Application" tab and make sure "Target Framework" does not have "client profile" in the name . . . that is should be ".NET Framework 4" not ".NET Framework 4 Client Profile".
I have not found this solution anywhere else, but stumbled upon it as a trial-and-error-by-fire...
The error message was a bit misleading in my situation. The tip off was that it wasn't really the "System.Windows" assembly itself, but one of the dependant assemblies.
What you may want to do is to check your GAC and see if one of these assemblies are in it:
- System.Windows
- System.Windows.Controls
- System.Windows.Controls.Toolkit
- System.Windows.Controls.Layout.Toolkit
Try removing them from just the GAC, then do your rebuild. If it doesn't work, just open two windows explorer windows and copy them back from either the c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll folder or the folder for your Silverlight Toolkit and you'll be back to where you started from.
Here's what I suspect is happening: The Visual Studio 2010 compiler is getting confused about where to get those referenced assemblies when doing the build because the GAC assemblies always takes precedence over another copy of an assembly (even the reference assembly folder that VS2010 uses). So even though the assembly is technically correct with the same ID key and everything there's something with the VS2010 compiler that can't determine which library to use for building and it will refuse to complete the build.
mmmm sometimes you put your classes in different project for example you can create a project for viewmodels , if is this the case then you need to reference PresentationCore.dll , this is the dll that give you access to System.windows so you can use ICommand for command bindings
精彩评论