The Background:
bin\debug\netcoreapp31\
and bin\release\netcoreapp31\
folders.What I have tried:
PackageReference
entries in the .csproj
file is correct. 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?
The issue turned out to be the culture on the NuGet package itself.
The culture on the NuGet package was set to "en-US", while the culture on the consuming assembly was set to neutral (""). This prevented the consuming assembly from being able to load the NuGet package's assembly at runtime.
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.)