.net core 3.1 app OK in VS, generates typeload error when published to local folder

Carlin Anderson 21 Reputation points
2021-01-26T20:09:11.643+00:00

I have a .net core 3 app which will run just fine from within VS 2019. As soon as I publish to my dev system reference it directly using IIS and hit the methods that start to do significant work, I will get the following error

System.TypeLoadException: Could not load type 'System.Xml.Linq.Extensions' from assembly 'System.Diagnostics.StackTrace, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

If I take the folder and copy it to another QA system, I get the same result.

How can I identify the differences between the debug VS2019 instance that is working OK vs. the published instance on the same system which generates the above error so it can be corrected?

UPDATE - Runtime is installed on the QA system; I would expect my dev system to already have everything needed, but maybe not....
Part of the app - only when I get to the XML/XDocument calls where I get the load failure. No inner exception in the error.
NOTE that the assembly has changed - one of the challenges I have also seen - its not consistent.
Connection ID "17005592203151542487", Request ID "800008d8-0002-ec00-b63f-84710c7967bb": An unhandled exception was thrown by the application.
Exception:
System.TypeLoadException: Could not load type 'System.Xml.Linq.Extensions' from assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=3.1.11.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at myfuctioncalla(Int32 a, String b, String filename)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.StartTStateMachine
at myfuctioncalla(Int32 a, String b, String filename)
at myfuctioncallMain(String b)
at Microsoft.AspNetCore

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,135 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 49,701 Reputation points
    2021-01-26T21:42:35.7+00:00

    To use .NET Core in IIS you need to ensure that the Web Host runtime is installed. If you installed the .NET Core SDK then it will install this but for a production machine you'll generally use the redist instead. It is recommended to use the Hosting Bundle on a production server rather than installing things separately as it installs both. Once you've installed the runtime you need to restart IIS for it to take effect. The instructions are given on the installation page.

    As for the exception the given type is throwing an exception when it's type constructor is running. If you look at the inner exception of TypeLoadException it will tell you specifically what is failing which will help indicate what is going wrong. One thing to look at is the binaries that are being used. Publishing should put the binaries together. This is done automatically when you build so you rarely see issues. However publishing is copying everything to a distribution folder and it may miss things so compare the binaries in the dist folders to what your build output expects.


0 additional answers

Sort by: Most helpful