0

Can an ASP.NET Core project target net461 and run on an Azure Website?


Here is what have been tried and failed.

It works when targeting netcoreapp1.0 but when I change it to net461(including some other needed changes to compile) I get the following error:

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.AppContext, 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.GetApplicationBasePath()
   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()
   at WebApplication1.Program.Main(String[] args) in C:\Users\a\WebApplication1\Program.cs:line 14

Specifically

System.IO.FileNotFoundException: Could not load file or assembly 'System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Locally it works fine.

I've naively added nuget packages to include the needed assemblies.

{
  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Newtonsoft.Json": "9.0.1",
    "System.AppContext": "4.1.0",
    "System.Reflection.TypeExtensions": "4.1.0",
    "System.Security.Cryptography.X509Certificates": "4.1.0"
  },

Eventually I got a different kind of errors:

warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to http://localhost:7762 on the IPv6 loopback interface.
System.AggregateException: One or more errors occurred. ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4089 EAFNOSUPPORT address family not supported
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.Check(Int32 statusCode)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener.CreateListenSocket()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<>c.<StartAsync>b__6_0(Object state)
   --- End of inner exception stack trace ---

I'm not sure where to go from here.

1 Answer 1

2

Although the publish profile had the option checked to "remove additional files at destination" there must still have been some files left.

Using FTP and manually delete all files before publishing solved the project.

ASP.NET Core targeting net461 works on Azure assuming you have not published any other frameworks there previously.

These NuGet packages I added in the question was not needed either and can safely be removed from the project.

"System.AppContext": "4.1.0",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Security.Cryptography.X509Certificates": "4.1.0"
Sign up to request clarification or add additional context in comments.

1 Comment

As an aside, you can also use Kudu Console, which is more convenient than FTP to view/manage your files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.