Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ASP.NET Core web application targeting full dotnet framework work in IIS?

I am trying to publish an ASP.NET Core application developed on top of full framework (4.6.1) to IIS. Right now the code is just the base template code created using the Visual Studio "ASP.NET Core (.NET Framework) option. The code compiles fine but when I publish it to Local IIS, it fails to start. I get error like

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Extensions.PlatformAbstractions.PlatformServices' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.Extensions.PlatformAbstractions.ApplicationEnvironment.GetEntryAssembly()
   at Microsoft.Extensions.PlatformAbstractions.ApplicationEnvironment..ctor()
   at Microsoft.Extensions.PlatformAbstractions.PlatformServices..ctor()
   at Microsoft.Extensions.PlatformAbstractions.PlatformServices..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()

My project.json looks like this

    {
  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net461": { }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

The same application if targeted towards dotnetcore instead of dotnet461 works fine. All MS documentation seems to say that this scenario is possible and is supported. Has something changed in RTM?

like image 569
JBA Avatar asked Jul 07 '16 04:07

JBA


People also ask

Can ASP.NET Core run on IIS?

The module allows ASP.NET Core apps to run behind IIS. If the Hosting Bundle is installed before IIS, the bundle installation must be repaired. Run the Hosting Bundle installer again after installing IIS.

Can I use .NET Core and .NET framework together?

NET Core is portable, and can be tuned to run across different supported platforms. Depending on how you target your projects, it's possible to have . NET Core code run on the . NET Framework, Mono and Xamarin platforms, on Windows 8 and Windows Phone, and on the Universal Windows Platform (UWP).

Do you need IIS for .NET Core?

Since Microsoft's IIS (Internet Information Services) web server only runs on Windows, you may be wondering why we would need to know about IIS-specific hosting at all. Well, we don't need IIS to run ASP . NET Core, but there are some useful IIS features you can take advantage of.


1 Answers

If you published the same application targeting netcoreapp1.0 first and then you the net4x version then I think it is a bug in Web Deploy. I hit a similar problem when publishing to Azure - https://github.com/aspnet/Hosting/issues/801#issuecomment-227920473. I fixed it by first manually deleting all the contents in the target folder and then publishing the application targeting net4x again (https://github.com/aspnet/Hosting/issues/801#issuecomment-228123238). I think Web Deploy leaves some dlls behind or does not update if the names are the same and they are then picked up but fail because they are not matching the target framework and their dependencies are missing. I also found that checking the checkbox in Web Deploy to delete files at the destination did not fix the problem and opened an issue on that.

like image 200
Pawel Avatar answered Oct 13 '22 12:10

Pawel