Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly > 'System.Windows, Version=2.0.5.0

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.

like image 466
Behnam Avatar asked Jun 05 '11 22:06

Behnam


4 Answers

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

like image 174
Mallory Avatar answered Sep 23 '22 12:09

Mallory


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);
                        }
                    }
                }
            }
like image 21
Evalds Urtans Avatar answered Sep 20 '22 12:09

Evalds Urtans


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

like image 23
Rahimi Avatar answered Sep 22 '22 12:09

Rahimi


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.

like image 30
Ankur Bhutani Avatar answered Sep 20 '22 12:09

Ankur Bhutani