Cosmos DB .NET SDK:找不到从未存在过的'resources.dll'



是的,我知道这个问题看起来类似于c# - '资源' DLL无法加载,因为它不存在,但我的问题是关于我不拥有的DLL。另一个问题涉及到作者自己编写的DLL。

编辑:在解决了这个问题之后,结果是完全相同的场景。我把自己的问题标记为重复。

的背景我正在写一个使用Cosmos DB . net SDK 3.32.2的c#库。有时,这个库会抛出异常,因为它找不到Microsoft.Azure.Cosmos.Direct.resources.dll。此文件不存在首先;Cosmos.DirectDLL附带的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:FooBarMicrosoft.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包时,我错过了与文化相关的设置。

这不是Cosmos的错;我们实际上有一个AppDomain。在其他地方注册的AssemblyResolve处理程序正在拦截程序集加载,即使它们是嵌入式程序集,并试图从特定位置将它们加载为.dll文件。这个文件不存在,所以会失败。

我最初在问题中提到的那个SO帖子?c# - 'Resources' DLL不存在导致加载失败

它确实解决了这个问题。只需在repo中搜索AssemblyResolve,检查是否为它注册了处理程序函数,然后确保处理程序在遇到嵌入式资源集之一时返回null(或nullptr,如果在c++中)。

相关内容

最新更新