Our Azure App Service fails to start with below error: Could not load file or assembly 'System.Diagnostics.DiagnosticSource

zhuq 11 Reputation points
2022-10-05T05:58:35.127+00:00

Our Azure App Service fails to start with below error:

Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

We followed a few recommended solution by the community and attempted to run the website by turning off the 'app insight', when this solution is applied, the error disappears but the website doesn't load. but if we turn it back on, the error reappears.

we are using .NET Framework 4.7.2 web application.

Ref

https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/1008

https://windows-hexerror.linestarve.com/q/so67600522-when-installing-application-insights-it-keeps-complaining-about-diagnosticsource-package-version

https://learn.microsoft.com/en-us/azure/azure-monitor/app/web-app-extension-release-notes

your help will be appreciated 247623-microsoftteams-image-2.png

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,021 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. VenkateshDodda-MSFT 22,401 Reputation points Microsoft Employee
    2022-10-06T07:51:22.887+00:00

    @zhuq Thank you for reaching out to Microsoft Q&A. Apologize for the inconvenience caused on this.

    Can you check the contents of the \bin folder for hosted web app. If you do NOT have System.Runtime.CompilerServices.Unsafe.dll in bin folder, then try to remove the <bindingRedirect/> setting from the web.config file and then the app will pick up the newer version that our extension brings.

    If you don't want to remove the <bindingRedirect/> setting then please try changing the binding redirect version in your web.config file in your app service to below

     <dependentAssembly>  
        <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />  
        <bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1"/>  
    </dependentAssembly>  
    

    if you have file System.Runtime.CompilerServices.Unsafe.dll in your \bin folder, then as a workaround, you can revert to the older App Insights extension version by going into App Service settings and manually set ApplicationInsightsAgent_EXTENSION_VERSION = 2.8.43

    Feel free to reach back to me if you have any questions on this.


  2. Maciej Skierski 0 Reputation points
    2023-11-28T00:10:22.2666667+00:00

    I'm not sure if this is going to help anyone but I had the same issue when instrumenting an old web site. I traced this to a tag in web.config

    <assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
    

    After removing ****appliesTo **** attribute, dll redirection and load started to worked.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.