简体   繁体   English

来自 NuGet package 的运行时异常引用类型:'无法加载文件或程序集'Foo'。 该系统找不到指定的文件。'

[英]Runtime exception referencing type from a NuGet package: 'Could not load file or assembly 'Foo'. The system cannot find the file specified.'

The Background:的背景:

  1. Consuming application is a website built using .NET Core 3.1.消费应用程序是使用 .NET Core 3.1 构建的网站。
  2. Consuming application references a NuGet package built using .NET Standard 2.0.使用 NuGet package 使用 .NET 标准 2.0 构建的应用程序引用。
  3. The consuming application has a reference to the latest version of the NuGet package and builds without any errors or warnings.消费应用程序引用了最新版本的 NuGet package 并且构建时没有任何错误或警告。
  4. The DLL from the NuGet package is visible in the bin\debug\netcoreapp31\ and bin\release\netcoreapp31\ folders. NuGet package 中的 DLL 在bin\debug\netcoreapp31\bin\release\netcoreapp31\文件夹中可见。
  5. In the IDE, full IntelliSense for the types in the NuGet package is available, including the XML Documentation comments for types, methods, and parameters. In the IDE, full IntelliSense for the types in the NuGet package is available, including the XML Documentation comments for types, methods, and parameters.
  6. At runtime, at the first reference to any type in the NuGet package, a FileNotFound exception is thrown, reporting that the DLL from the NuGet package file cannot be found. At runtime, at the first reference to any type in the NuGet package, a FileNotFound exception is thrown, reporting that the DLL from the NuGet package file cannot be found.

What I have tried:我试过的:

  1. Verifying that the PackageReference entries in the .csproj file is correct.验证.csproj文件中的PackageReference条目是否正确。 Since it's a .NET Core application, there are no hint paths or assembly binding redirects that are interfering with assembly binding.由于它是 .NET 核心应用程序,因此不存在干扰程序集绑定的提示路径或程序集绑定重定向。
  2. Clearing the NuGet cache.清除 NuGet 缓存。
  3. Removing and re-adding the NuGet package.删除并重新添加 NuGet package。
  4. Forcing NuGet to reinstall the package through the Package Manager Console.通过 Package 管理器控制台强制 NuGet 重新安装 package。
  5. Cleaning and rebuilding the solution.清理和重建解决方案。
  6. Enabling Fusion Log Viewer and combing through the logs.启用 Fusion Log Viewer 并梳理日志。 This is where things get interesting.这就是事情变得有趣的地方。 There are no entries in the logs indicating any attempts to resolve or load the assembly, or any entries indicating that the assembly bind failed.日志中没有指示任何尝试解析或加载程序集的条目,或任何指示程序集绑定失败的条目。

Exception Message异常消息

Could not load file or assembly 'OneCall.FeatureFlags, Version=1.0.0.0, Culture=en-US, PublicKeyToken=null'. The system cannot find the file specified.
   at PTWebAPI.Startup.ConfigureServices(IServiceCollection services) in C:\Dev\PTWebAPI\PTWebAPI\Startup.cs:line 65
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass15_0.<BuildStartupServicesFilterPipeline>g__RunPipeline|0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass14_0.<ConfigureServices>g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at PTWebAPI.Program.Main(String[] args) in C:\Dev\PTWebAPI\PTWebAPI\Program.cs:line 15

Point of Failure故障点

public static void Main(string[] args)
{
   CreateWebHostBuilder(args).Build().Run(); // <-- Right here
}

The Question问题

What causes this particular exception when loading an assembly in a .NET Core application, and how do you resolve it?在 .NET 核心应用程序中加载程序集时,是什么导致了这个特殊的异常,您如何解决它?

The issue turned out to be the culture on the NuGet package itself.问题原来是 NuGet package 本身的文化。

The culture on the NuGet package was set to "en-US", while the culture on the consuming assembly was set to neutral (""). NuGet package 上的区域性设置为“en-US”,而消耗组件上的区域性设置为中性(“”)。 This prevented the consuming assembly from being able to load the NuGet package's assembly at runtime.这阻止了消费程序集能够在运行时加载 NuGet 包的程序集。

The solution was to set the culture on the NuGet package to neutral (""), republish the package, and update the package reference in the consuming assembly. The solution was to set the culture on the NuGet package to neutral (""), republish the package, and update the package reference in the consuming assembly.

(Thanks to Hamlet Hakobyan for pointing me in the right direction.) (感谢Hamlet Hakobyan为我指明了正确的方向。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集&#39;Microsoft.Bot.Builder,版本= 3.4.0.0,系统找不到指定的文件。”, - Could not load file or assembly 'Microsoft.Bot.Builder, Version=3.4.0.0, The system cannot find the file specified.", 无法加载文件或程序集或其依赖项之一。 该系统找不到指定的文件。 (不允许GAC) - Could not load file or assembly or one of its dependencies. The system cannot find the file specified. (No GAC allowed) '无法加载文件或程序集。 系统找不到指定的文件' - 打包后抛出 .NET 框架 NuGet package - 'Could not load file or assembly. The system cannot find the file specified' - thrown after packaging .NET Framework NuGet package 尝试通过反射加载应用程序并显示错误“无法加载文件或程序集…系统找不到指定的文件。” - Trying to load an app through reflection and get error “Could not load file or assembly…The system cannot find the file specified.” 软件包管理器&gt;系统找不到指定的文件。 (来自HRESULT的异常:0x80070002) - Package Manager > The system cannot find the file specified. (Exception from HRESULT: 0x80070002) “无法加载文件或程序集&#39;XXX.YYY&#39;或其依赖项之一。 该系统找不到指定的文件。” - “Could not load file or assembly 'XXX.YYY' or one of its dependencies. The system cannot find the file specified.” 无法加载文件或程序集'Oracle.Web,Version = 2.112.1.0 ...系统找不到指定的文件。 (它已经加载到我的GAC中) - Could not load file or assembly 'Oracle.Web, Version=2.112.1.0… The system cannot find the file specified. (It's already loaded in my GAC) 无法加载文件或程序集“ * .dll”,系统找不到指定的文件 - Could not load file or assembly “*.dll” , The system cannot find the file specified Sharepoint“无法加载文件或程序集”“系统找不到指定的文件” - Sharepoint “Could not load file or assembly” “The system cannot find the file specified” 无法加载文件或程序集'msshrtmi,系统找不到指定的文件 - Could not load file or assembly 'msshrtmi, The system cannot find the file specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM