1

I have recently updated my site on IIS with changes that I made, with the update I did not do any nuget package upgrades or added any new assemblies to the project but I am now getting the following error when I browse any page enter image description here

I checked first in event log and I found the following error

Application 'MACHINE/WEBROOT/APPHOST/WWW.N1CORE.CO.ZA' with physical root 'C:\Websites\beta.n1plus.co.za\' failed to start process with commandline 'C:\Websites\beta.n1plus.co.za\n1Plus.n1Plus.Web.Host.exe ', ErrorCode = '0x80004005 : e0434352.

I found a few answers on the error code but all of them was to the version of DotNetCore installed which is not the solution to my problem. I have done further testing and added a try catch over my code like follow:

public class Program
{
    public static void Main(string[] args)
    {
        try
        {
            var host = new WebHostBuilder()
                .UseKestrel(opt => opt.AddServerHeader = false)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
        catch (System.Exception ex)
        {
            System.Console.WriteLine(ex.Message);
            System.Console.WriteLine(ex.StackTrace);
        }
    }
}

The above code has given me the following error

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at n1Plus.n1Plus.Web.Startup.Program.Main(String[] args)

I have reverted back to the old code and the error went straight away, however when I compare the installed version of System.Runtime.InteropServices.RuntimeInformation it is the same version on both old and new (with the changes)

I have tried the solution stated in the link

Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation

<dependentAssembly>
 <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
 <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
Donald Jansen
  • 1,937
  • 4
  • 22
  • 41
  • You don't need `UseKestrel` when you're running directly within IIS btw. – Dai Nov 25 '21 at 18:57
  • Removing it doesn't really fix the problem :( – Donald Jansen Nov 25 '21 at 19:06
  • Exactly what version of ASP.NET Core are you using? And what .NET runtime target are you using? Have you ensured your VS is updated? Have you nuked your deployment target directory (always completely nuke-from-orbit your deployment folder, otherwise leftover files can break things exactly like this). – Dai Nov 25 '21 at 21:45
  • The project build on https://aspnetzero.com/ is using Dotnet Webhosting 2.0.5, and the project is on Net461, problem I find is that I havent done any upgrades, or added any new assemblies if I load the previous build it works, I have even compared the config files of both builds. I cleared my build (debug/release) bin and also the obj folder, I also cleared the publish folder. – Donald Jansen Nov 26 '21 at 05:56
  • .NET 4.6.1? That's really out of date. I'm assuming then your project is an ASP.NET Core 1.x or ASP.NET Core 2.x project running on .NET Framework? That's going to cause a heap of potential problems with dependencies: assembly binding etc – Dai Nov 26 '21 at 06:39
  • 1
    I recommend you update your project to ASP.NET Core 3.1 on .NET Core 3.1 (_not_ .NET Framework) - that will eliminate this problem entirely. – Dai Nov 26 '21 at 06:40
  • 1
    Found the issue, for somereason after uninstalling VS2022 it worked again. even though I had it installed for over a month, maybe a new updated caused the issue – Donald Jansen Nov 28 '21 at 07:14
  • Have you enabled the 'Ready to run' setting, when you publish? – Poul Bak Nov 28 '21 at 20:22

0 Answers0