C# – 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=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.":"System.Windows, Version=, 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.

Best Solution

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.