Search code examples
asp.netvb.netnugetazure-application-insights.net-framework-version

Installing NuGet package causes server error in application (ASP.NET on .NET Framework)


I have an ASP.NET web application targeting .NET Framework 4.6.2 (VB.NET, not C#). I'm running it locally with IIS.

When I installed Microsoft.ApplicationInsights 2.21.0 using NuGet and re-loaded the site locally, I received a server error:

Server Error in '/' Application. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Three considerations:

  1. I didn't change any code- I just installed the package.

  2. The dependency tree NuGet installed for Microsoft.ApplicationInsights 2.21.0 in this project included:

System.Buffers.4.5.1
System.Numerics.Vectors.4.5.0
System.Runtime.CompilerServices.Unsafe.5.0.0
System.Memory.4.5.4
System.Diagnostics.DiagnosticSource 5.0.0
Microsoft.ApplicationInsights.2.21.0

None of those pre-existed in my project, so I'm certain I only installed new packages which shouldn't conflict or crossover with any pre-existing dependencies.

  1. There are no build errors when rebuilding the project. It only throws the above error on the web page.

I tried wiping the bin and obj folders, and restarting IIS. Didn't help.

I configured NuGet to restore packages and deleted all of the packages in the solution and rebuilt it. That didn't help, either.

The project has deprecated packages. However, they have nothing to do with AppInsights, and I'd like to avoid a re-write if possible.

Generally, it seems like there is a dependency conflict within one or more dependency tree(s) that reference one or more assemblies in the GAC, but I have no clear way of identifying the tree(s) or fixing it/them.

How can I diagnose which package/assembly is causing this error if none of the new packages was referenced by any existing one?


Solution

  • Server Error in '/' Application. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

    As you mentioned, the error could be due to the compatibility or conflicts between the error and also there must be some issues with the application code.

    • Try upgrading the existing package versions to be compatible with the Application Insights package version.
    • To know the exact error, check LoaderExceptions property or handle the exceptions with try, catch block in your application.
    • Refer SO to handle the LoaderExceptions.

    Try configuring Application Insights Manually, refer MSDOC:

    • Right click on the project=>configure Application Insights:

    enter image description here

    • Select Application Insights sdk=>Next=>Finish=>Close.
    • Add your Application Insights connection string in ApplicationInsights.config before the closing tag .
        <ConnectionString>your_application_insights_connection_string</ConnectionString>    
    </ApplicationInsights>
    

    I tried installing the Application insights package version 2.21.0 in my .NET web application version 4.8 (vb.net). I could run the application without any issues:

    References of my project:

    enter image description here