Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
I am seeing a ton of people hitting this when using netcoreapp1.1
. (See #7869, #7557, #7742, #7358 & #5627) We thought dotnet/corefx#15031 was going to fix it, but there must be another underlying issue somewhere.
Looks like this only occurs on Class Library projects targeting netcoreapp1.1
. The issue is that we fallback to using ef.runtimeconfig.json
which targets Microsoft.NETCore.App
version 1.0.0.
You can workaround the issue by forcing a runtime config to be generated by the project. This avoids falling back to running on 1.0. To do this, add the following to the project's *.csproj
<PropertyGroup>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
Thanks a lot @bricelam, this workaround fixed the problem I was having with dotnet ef database update
command on a Class Library project targeting netcoreapp1.1
that was driving me crazy! Thanks again!
It works for me, thanks @bricelam
Thank you @bricelam. I was about to punch a hole through my computer screen until I found your work around.
@bricelam please at least you could add some friendly messages to guide user what to do and how to solve it. This exception is very confusing and eat a lot of time. Also why netstandard1.6 doesn't work with migration?
Thanks @bricelam, it works....
Thank you a lot @bricelam it really worked !
Note, a fix has been checked into dev
and should be available soon on the nightly build feed.
It works for me too. Thanks @bricelam !!
I have spent a lot time to solve the issue! So, let's go ahead !
Using the workaround for now. Thanks!
It works for me too @bricelam, Thanks!
Re-opening. We probably need to update the PMC tools too.
@Eilon Looks like this also got the "patch-proposed" label last week, but for 1.0.4. @bricelam is this something we really need to put in 1.0.x patches? Let's discuss tomorrow.
Technically, it's in the 1.0.1 release of dotnet-ef (there is no 1.1.0).
This patch fix is approved. Please follow the normal code review / pull request process and make sure you make the change in the correct branch.
Preview builds of this patch fix should be available on the following feeds:
If you have a chance, please try out these preview builds and let us know if you have any feedback!
Verified fixed in the 1.0.1 candidate build of dotnet-ef.
I just installed System.Diagnostics.DiagnosticSource and System.Collections.Immutable from the NuGet Package Manager, and everything is working :)
Any suggestions when calling Migrate()
in a WinForms App? Whenever Migrate()
is called I receive the exception "could not load....".
I cannot work around with a "-s" switch in that case, so does anybody have another hint for me what I could try to get my software back working? (I only updated because I got "DB connection closed due to ROLLBACK using the .Include
and .ThenInclude
things which hopefully are fixed now...)
i am using vs 2017. I got same error and fixed with @bricelam replies. Thanks. After adding code below, you should run clean solution and rebuild solution.
<PropertyGroup>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
hmmm. did it for the main program and for my library that uses System.Diagnostics...
No success. I think I am missing something...
...the myprogram.exe.config still contains
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
but should that not look like anything 4.3.2 ???
This was a great help. Thank you!
I'm still seeing this issue.
My main console app and related data access class library (that contains my DbContext) are both targeting .NET Core 2.0.
Nothing I can see references 4.0.2.1.
Both projects have 4.4.1 of System.Diagnostics.DiagnosticSource installed, and both have the GenerateRuntimeConfigurationFiles
workaround added.
EDIT: I'm using v2.0.0 of all EntityFrameworkCore packages
@robinchesterman Have you installed the .NET Core 2.0 SDK?
@bricelam hello, I met the same issue as @robinchesterman when using EF Core 2.0 with .Net Core 2.0. The problem occurs after I upgraded from 2.0-preview2 to 2.0-rtm.
You can reproduce the problem here in my repo:
https://github.com/gridsum/DataflowEx/releases/tag/efcore-issue-7889
Just build and run tests which will fail with:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Thanks.
@karldodd - Your issue is in this file https://github.com/gridsum/DataflowEx/blob/efcore-issue-7889/global.json
By using global.json you are forcing VS to use 2.0.0-preview2 .net SDK. Hence you are hitting the issue. Update your global.json (or delete it if 2.0.0 RTM is in your path) to resolve the issue.
I have this issue only when running tests under JetBrains Rider 2017.2 EAP.
Using dotnet test
it works just fine.
I have 2.0 SDK and no preview version installed in this device.
If I remember correctly, this issue went away when I installed .NET Core SDK 2.0.1
@smitpatel Nice catch! It is the global.json issue. The exception is gone after switching global.json to 2.0.0 rtm. Thanks a lot for your help.
Same problem for me, but with windows service project in a production environmnet.
I've posted here:
https://stackoverflow.com/questions/47894004/error-in-net-framework-app-using-4-6-1-with-system-diagnostics-diagnosticssourc
I have a window service project (4.6.1) referencing Net Standard (2.0) projects that contain EntityFrameworkCore dll.
EDIT: Solved for me.
I see this is closed, but wasted hours on the same issue. Fortunately one comment referred to an issue with .Net 4.7.1. They incorporate some types into the main framework not previously there. Those types existed in the source used for latest service bus as of 8/16/2018 so they do not play together nor give a reasonable error to let you know why. I retargeted entire solution to .Net 4.7 and no more error. I almost went down the road of modifying latest version of the service bus interops, but it is bulky and even used some language constructs not supported in the latest released c#. Hopefully, a new service bus comes out at some point -- until then, would avoid 4.7.1 if you need service bus sdk.
Most helpful comment
Looks like this only occurs on Class Library projects targeting
netcoreapp1.1
. The issue is that we fallback to usingef.runtimeconfig.json
which targetsMicrosoft.NETCore.App
version 1.0.0.Workaround
You can workaround the issue by forcing a runtime config to be generated by the project. This avoids falling back to running on 1.0. To do this, add the following to the project's
*.csproj