问题
Windows Error Log:
failed to load coreclr. Exception message: CLR worker thread exited prematurely
Details:
Application 'EnterpriseReportsAPI' with physical root '...\Repos\InternalReportsAPI\EnterpriseReportsAPI' failed to load coreclr. Exception message: CLR worker thread exited prematurely
Process Id: 10688. File Version: 13.1.19350.1. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: e276c8174b8bfdeb70efceafa81c75f8badbc8db
Every thing works more or less fine until I try to further the dependency injection by changing my static connectionstring helper into an injected service.
public class Connections : IConnections
{
private readonly ISecurityServiceHelper _securityServiceHelper;
public Connections(ISecurityServiceHelper securityServiceHelper)
{
_securityServiceHelper = securityServiceHelper;
}
public string GetSqlConnectionString(string[] creds)
{
return _securityServiceHelper.GetSqlConnectionStringAsync(creds).Result;
}
}
Then in the startup.cs I change it to:
public Startup(IConfiguration configuration, IConnections connections)
{
Configuration = configuration;
Connections = connections;
}
private readonly IConfiguration Configuration;
private readonly IConnections Connections;
Then utilize those properties inside the following:
string[] creds =
{
Configuration.GetSection("ApplicationCreds").GetSection("appId").Value,
Configuration.GetSection("ApplicationCreds").GetSection("appToken").Value,
Configuration.GetSection("ConnectionString").GetSection("connectionString").Value
};
services.AddDbContext<InternalReportsContext>(options =>
options.UseSqlServer(Connections.GetSqlConnectionString(creds)));
I have declared the two services as follows:
services.AddScoped<IConnections, Connections>();
services.AddScoped<IConfiguration>(sp =>
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("appsettings.json");
return configurationBuilder.Build();
});
So I have looked at a few posts (notably [this])(HTTP Error 500.30 - ANCM In-Process Start Failure) on changing the InProcess to OutOfProcess however that gives me other weird issues. I am not sure what changes when I make these changes under the hood and it has been driving me crazy for several days.
I had started the API in 2.2 but it is now 3.1.1 and I removed all the 2.2 references from the csproj file as well.
If I change the properties to OutOfProcess as suggested by the other "related" post I get the following:
This seems to be very close to my issue but I can't figure out which reference has a dependency on the Core 2.2. I have removed all the 2.2 references from the csproj and I don't see anything that jumps out in my references. Or I am looking in the wrong place.
来源:https://stackoverflow.com/questions/64994567/http-error-500-30-ancm-in-process-start-failure-on-a-localhost-net-core-3-1-1