.NET 2.0 vs .NET 4.0 loading error
My class library is compiled against .NET 2.0 and works just fine whenever I try to load it as a plugin under the 2.0 runtime. If however the master application is running the .NET 4.0 runtime, I get an exception as soon as the resources need to be accessed:
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)
a开发者_运维百科t 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
....
What's going on and how do I make my project load on all .NET Runtimes?
EDIT: The problem was an AssemblyResolver I wrote that got confused when asked to load "Grasshopper.resources". It seems that .NET 4.0 handles resource loading differently from earlier runtimes???
Adding a test for resource assemblies to an AssemblyResolver fixes the issue and allows me to run this class library under both .NET 2.0 and 4.0:
private Assembly ResolveGrasshopper(object sender, ResolveEventArgs e)
{
if (e.Name.Contains(".resources,")) { return null; }
....
}
精彩评论