Azure Storage blobs Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd

Viewed 1818

I have a console app program on .Net core 2.2 to upload a file to the Azure blob storage. It's completely ok and working on my local computer, But when I deploy the app to the Azure app service, it throws an exception with this error:

Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd the problem is on this line of code:

BlobServiceClient storageAccount = new BlobServiceClient("connection string")

I tried to change the versions of System.Diagnostics.DiagnosticSource and Azure.Storage.Blobs but it didn't work on the Azure app service

Edit: I didn't find any solution for the problem, I change the code so that use Azure storage from the aps.net core app.

1 Answers

3 Possible ways that may solve this issue

1. Install-Package System.Diagnostics.DiagnosticSource -Version 4.4.1 and add nuget package System.Net.Http 4.3.1 to the project. Then restart and run again.

2. In the web.config file, add the following bindingRedirect tag:

<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 are using app.config , remove all binding redirects and addbelow property up on the top.)

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

Save this and restart the app service and run the installation again.

See if this works ,other wise go for 3

3. Disable Application Insights using the Portal. Restart and run again.

Also try adding below property group to the *.csproj file

<PropertyGroup>
  <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

Related