2010-06-10 79 views
4

我的類庫是針對.NET 2.0編譯的,只要我試圖在2.0運行時下載它作爲插件就可以工作。然而,如果主應用程序運行在.NET 4.0運行時,我只要資源需要訪問得到一個異常:.NET 2.0 vs .NET 4.0加載錯誤

Exception occurred during processing of command: Grasshopper 
Plug-in = Grasshopper 
Could not find file 'Grasshopper.resources'. 

CALL STACK 
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark) 
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark) 
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark) 
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) 
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) 
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream) 
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture) 
at Grasshopper.My.Resources.Resources.get_GrasshopperBannerImage_Palette() in D:\dev\grasshopper\1.0\root\src\My Project\Resources.Designer.vb:line 1159 
at Grasshopper.GUI.GH_Banner.ExplicitBanner_Load(Object sender, EventArgs e) in D:\dev\grasshopper\1.0\root\src\GH_Banner.vb:line 14 
.... 

這是怎麼回事?我如何使所有的.NET運行時我的項目負荷?

編輯: 問題是我寫的一個AssemblyResolver,當被要求加載「Grasshopper.resources」的時候被弄糊塗了。似乎.NET 4.0處理資源加載與早期運行時不同?

+3

這是.NET。不是DotNet。 – 2010-06-10 19:36:32

回答

4

添加對資源集合到一個AssemblyResolver測試修復該問題,並讓我在兩個.NET 2.0和4.0上運行這個類庫:

private Assembly ResolveGrasshopper(object sender, ResolveEventArgs e) 
{ 
    if (e.Name.Contains(".resources,")) { return null; } 
    .... 
} 
+0

感謝您的跟進。 – Greg 2010-06-11 14:33:58