[英]Runtime exception referencing type from a NuGet package: 'Could not load file or assembly 'Foo'. The system cannot find the file specified.'
The Background:的背景:
bin\debug\netcoreapp31\
and bin\release\netcoreapp31\
folders. bin\debug\netcoreapp31\
和bin\release\netcoreapp31\
文件夹中可见。 What I have tried:我试过的:
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. 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.