我的类库是针对.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处理资源加载的方式与早期的运行时有所不同?
发布于 2010-06-11 18:00:17
将资源程序集的测试添加到AssemblyResolver修复了这个问题,并允许我在.NET 2.0和4.0下运行这个类库:
private Assembly ResolveGrasshopper(object sender, ResolveEventArgs e)
{
if (e.Name.Contains(".resources,")) { return null; }
....
}https://stackoverflow.com/questions/3017603
复制相似问题