2011-06-05 70 views
4

在我的Silverlight應用程序我不斷收到此錯誤的第一負載:無法加載文件或程序集>「System.Windows,版本= 2.0.5.0

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

但剛剛刷新頁面,它會解決!

看來,它被稱爲Silverlight中的漏洞: http://connect.microsoft.com/VisualStudio/feedback/details/464190/silverlight-compilation-problem-in-team-build-environment

他們提出的解決方法,但對我來說不起作用。

回答

7

實際上,'System.Windows'程序集複製到輸出目錄解決了我的問題。只要確保將它複製到無論您將要執行您的應用程序,而不僅僅是Debug文件夾。也有是不存在類似的問題一個很好的替代:SilverUnit

0

只需添加這個dll 的參考System.Windows.Presentation.dll到你的項目爲您的項目是要求System.Windows.dll中它是包含在System.Windows.Presentation.dll中的命名空間。

路徑的dll的是:

C:\ WINDOWS \ Microsoft.NET \裝配\ GAC_MSIL \ System.Windows.Presentation \ v4.0_4.0.0.0__b77a5c561934e089

我也曾經面臨這個問題,加入我的項目已經解決了這個問題。

感謝,

ANKUR不丹

0

檢查,如果你有一些代碼某處這樣

Assembly assembly = Assembly.Load(assemblyName); 

如果你擁有了它,這意味着它可能被裝載不當的AssemblyName像System.Windows其他。 net framework

在這種情況下,您可以直接使用引用的庫或從正確的assemblyName中加載它,如下所示

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); 
         } 
        } 
       } 
      } 
1

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.

在設置屬性 複製本地項目的參考文件夾

真正你的彙編文件的 。

注:如果你的項目中使用.NET 2.0中使用的.NET Framework 2.0 SP2來解決這個問題

相關問題