问题
On first load of my Silverlight application I keep getting this error:
Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified
but by just refreshing the page, it'll be solved!
it seems that it's known bug of Silverlight : http://connect.microsoft.com/VisualStudio/feedback/details/464190/silverlight-compilation-problem-in-team-build-environment
they suggest workaround, but does not work in my case.
回答1:
Well actually 'System.Windows' assembly is copied to the output directory solved the problem form me. Just make sure that it is copied to whereever you're going to be executing your app, not just the Debug folder. Also there is a very good alternative that doesn't have similar problems: SilverUnit
回答2:
Check if you have code somewhere like this
Assembly assembly = Assembly.Load(assemblyName);
If you have it that means it might be loading inappropriate assemblyName like System.Windows for other .net framework
In that case you could use referenced library directly or load it from correct assemblyName something like this
foreach (var assemblyName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
if (assemblyName.ToString().Contains("PresentationFramework"))
{
Assembly assembly = Assembly.Load(assemblyName);
Common.AddToLog(assembly.FullName);
Type[] allTypes = assembly.GetTypes();
foreach (Type type in allTypes)
{
if (type.IsSubclassOf(typeof(DependencyObject)))
{
allControlTypes.Add(type);
}
}
}
}
回答3:
Blockquote Well actually 'System.Windows' assembly is copied to the output directory solved the problem form me. Just make sure that it is copied to whereever you're going to be executing your app, not just the Debug folder.
in the reference folder of your Project set Property Copy Local: true of your assembly file.
Note: if your project use .NET 2.0 use .NET Framework v2.0 SP2 to fix this problem
回答4:
Just add reference of this dll System.Windows.Presentation.dll into your project as your project is asking for System.Windows.dll and it is a namespace which is contained in System.Windows.Presentation.dll.
Path for the dll is :
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Windows.Presentation\v4.0_4.0.0.0__b77a5c561934e089
I do have faced this problem, adding this to my project have solved this problem.
来源:https://stackoverflow.com/questions/6246475/could-not-load-file-or-assembly-system-windows-version-2-0-5-0