此问题已在此处有答案:
C# - 'Resources' DLL failing to be loaded as it doesn't exist - How might I find the reference so that I can remove it?(3个答案)
4天前关闭。
是的,我知道这个问题看起来像C# - 'Resources' DLL failing to be loaded as it doesn't exist,但我的问题是关于一个DLL,**我不拥有。**另一个问题涉及作者自己写的DLL。
**编辑:**解决问题后,原来是完全相同的情况。我已经将自己的问题标记为重复。
背景
我正在写一个使用Cosmos DB .NET SDK 3.32.2的C#库。有时,这个库会抛出一个异常,因为它找不到Microsoft.Azure.Cosmos.Direct.resources.dll
。这个文件从一开始就不存在;Cosmos.Direct
DLL附带了en-US
不变区域性资源嵌入在DLL中。是的,我反编译了它以检查-Cosmos.Direct
似乎是Cosmos团队没有作为开源发布的SDK的一部分。
需要说明的是,我不控制Microsoft.Azure.Cosmos.Direct.dll
。这是我的依赖项。仅供参考,Microsoft.Azure.Cosmos
的NuGet包附带了四个DLL,其中一个是Microsoft.Azure.Cosmos.Direct.dll
。
FooBar.OurCustomExceptionType: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Foo\Bar\Microsoft.Azure.Cosmos.Direct.resources.dll' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
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, Dictionary`2 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.GetString(String name, CultureInfo culture)
at Microsoft.Azure.Documents.StoreResult.CreateStoreResult(StoreResponse storeResponse, Exception responseException, Boolean requiresValidLsn, Boolean useLocalLSNBasedHeaders, Uri storePhysicalAddress)
at Microsoft.Azure.Documents.StoreReader.<ReadMultipleReplicasInternalAsync>d__14.MoveNext()
... long stack trace ...
at FooBar.OurCustomCosmosWrapper`1.<GetItemAsync>d__4.MoveNext()
查看堆栈跟踪,库正在搜索从未存在过的资源的“附属程序集”,即使这些资源嵌入在DLL中。
我已经在AssemblyInfo.cs中设置了自己的应用程序使用[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
,但显然这不会影响Cosmos依赖库。它只会影响我自己的FooBar程序集,该程序集依赖于Cosmos SDK。
我的问题
如何强制我的一个依赖DLL(在本例中为Microsoft.Azure.Cosmos.Direct.dll)使用其自己的嵌入式资源,而不是尝试查找不存在的单独resources.dll
文件?
我敢打赌这可能是几个问题之一:
- 有一些方法可以在App.config或其他一些我不知道的项目配置文件中设置依赖程序集资源加载。记住:我不需要为我自己的库设置这个;我需要为我的一个依赖项设置这个。
- 这是Cosmos SDK中的一个bug。
- 在导入Microsoft.Azure.Cosmos包时,我在某处遗漏了与区域性相关的设置。
1条答案
按热度按时间mspsb9vt1#
这不是宇宙的错;我们实际上有一个在其他地方注册的AppDomain.AssemblyResolve处理程序,它正在拦截程序集加载,即使它们是嵌入式程序集,并试图从特定位置以.dll文件的形式加载它们。这个文件从未存在过,所以它会失败。
我最初在我的问题中提到的那个SO帖子?C# - 'Resources' DLL failing to be loaded as it doesn't exist
它确实解决了这个问题。只需在repo中搜索
AssemblyResolve
,检查是否为它注册了处理程序函数,然后确保处理程序在遇到嵌入式资源程序集时返回null
(或nullptr
,如果是C++)。