Reputation: 9380
I am trying to host a .NET Core
application with Kestrel
not on IIS
.And i seem getting the following error:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.AspNetCore.Server.IISIntegration, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'
MISC
class Address {
public string ProtocolType { get; set; } = "http";
public string Host { get; set; }
public long Port { get; set; }
public static Address Default = new Address { Host = "localhost", Port = 9300, ProtocolType = "http" };
}
static class AddressExtensions {
public static string ToUrl(this Address @this) {
return $"{@this.ProtocolType}//{@this.Host}:{@this.Port}";
}
}
Program
public class Program {
public static void Main(string[] args) {
CreateWebHostBuilder(args).Build().Start();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
var builder=WebHost.CreateDefaultBuilder(args); //crashes here !!
builder.UseStartup("Startup");
var url = Address.Default.ToUrl();
builder.UseKestrel().UseUrls(url);
return builder;
}
}
Startup
public class Startup {
public void ConfigureServices(IServiceCollection services) {
services.AddMvcCore();
}
public void Configure(IApplicationBuilder app) {
app.Map("/http", x => x.UseMvc());
app.Map("/ws", x => {
});
app.UseMvc();
}
}
Why does it try to host it on IIS
? I must specify that i do not have a launchSettings.json
file. It did not create one from the .NET Core App
template.Do i have to do it manually for running outside of IIS
?
How can i make this server work and run outside IIS
?
Upvotes: 0
Views: 318
Reputation: 239460
First, launchSettings.json
is only for development. It is not published and not used once the app is deployed.
Second, CreateDefaultBuilder()
, among other things, adds the IIS integration services. However, that doesn't mean that you have to host in IIS at that point. You certainly shouldn't be getting an error just because the IIS integration is included, but you're not hosting in IIS. If I had to hazard a guess, I'd imagine you're running a different version of the .NET Core SDK than the runtime that's installed on your server. Make sure that the two are in line with each other.
If you want to get rid of the IIS integration altogether, you'll need to stop using CreateDefaultBuilder
and do what it does manually, minus of course the adding of the IIS integration. You can view the source to see what the method is taking care of.
Upvotes: 1