.NET 2.0与.NET 4.0加载错误

4

我的类库编译时针对.NET 2.0,当我尝试在2.0运行时加载它作为插件时,它完全正常。但是,如果主应用程序正在运行.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处理资源加载与早期版本的运行时不同???

1个回答

4

将资源程序集的测试添加到AssemblyResolver中可以解决此问题,并允许我在.NET 2.0和4.0下运行此类库:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接