I try to get my .NETCore console application running but currently with no luck at all. It crashes with some strange errors.
First how can I inject configuration values? In my main (Programm.cs) I have
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(Environment.GetEnvironmentVariable("ASPNETCORE_URLS") ?? ListeningOn)
.Build();
host.Run();
My startup.cs
looks similar to the one shown here:
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration) => Configuration = configuration; // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseServiceStack(new AppHost
{
AppSettings = new NetCoreAppSettings(Configuration)
});
app.Run(context =>
{
context.Response.Redirect("/metadata");
return Task.FromResult(0);
});
}
}
Configuration
contains one item of type MemoryConfigurationProvider with defaults that I have never set:
Instead I like to have a Configuration loaded from a JSON file like so:
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
var config = builder.Build();
How can I pass my config
variable to the Startup.cs class?? I tried to use WebBuilder.AddConfiguration(config)....
but no luck with that.
No matter what configuration I add, it crashes here:
app.UseServiceStack(new AppHost
{
AppSettings = new NetCoreAppSettings(Configuration)
});
with
System.Exception: Failed loading types, last assembly ‘BizBusLicenseServer.ServiceInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’, type: ‘’ —> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at ServiceStack.Host.ServiceController.GetAssemblyTypes(Assembly[] assembliesWithServices)
— End of inner exception stack trace —
at ServiceStack.Host.ServiceController.GetAssemblyTypes(Assembly[] assembliesWithServices)
at ServiceStack.Host.ServiceController.<>c__DisplayClass5_0.<.ctor>b__0()
at ServiceStack.Host.ServiceController.Register(ITypeFactory serviceFactoryFn)
at ServiceStack.Host.ServiceController.Init()
at ServiceStack.ServiceStackHost.Init()
at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost)
at BizBusLicenseServer.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in /home/tbednarz/Projects/BizBusLicenseServer/BizBusLicenseServer/Startup.cs:line 24
The LoaderException
contains a list of assemblies I have added in my Dependencies:
Any idea what is missing here?
Do I need to set a Dependency path somewhere?
I run JetBrains Rider on CentOS 7.