Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not load System.Diagnostics.DiagnosticSource #7889

Closed
bricelam opened this issue Mar 15, 2017 · 32 comments
Closed

Could not load System.Diagnostics.DiagnosticSource #7889

bricelam opened this issue Mar 15, 2017 · 32 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@bricelam
Copy link
Contributor

bricelam commented Mar 15, 2017

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.

@bricelam
Copy link
Contributor Author

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.

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

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

@fbertin
Copy link

fbertin commented Mar 15, 2017

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!

@xepher
Copy link

xepher commented Mar 16, 2017

It works for me, thanks @bricelam

@ajcvickers ajcvickers added this to the 1.1.2 milestone Mar 17, 2017
@jhaacke
Copy link

jhaacke commented Mar 17, 2017

Thank you @bricelam. I was about to punch a hole through my computer screen until I found your work around.

@atonamy
Copy link

atonamy commented Mar 18, 2017

@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?

@nrubiano
Copy link

Thanks @bricelam, it works....

@DavidNorena
Copy link

Thank you a lot @bricelam it really worked !

@bricelam bricelam modified the milestones: 1.0.4, 1.1.2 Mar 21, 2017
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Mar 22, 2017
bricelam added a commit to aspnet/EntityFramework.Tools that referenced this issue Mar 22, 2017
bricelam added a commit to aspnet/EntityFramework.Tools that referenced this issue Mar 22, 2017
@bricelam
Copy link
Contributor Author

Note, a fix has been checked into dev and should be available soon on the nightly build feed.

@rmotzko
Copy link

rmotzko commented Mar 29, 2017

It works for me too. Thanks @bricelam !!

I have spent a lot time to solve the issue! So, let's go ahead !

@uoc1691
Copy link

uoc1691 commented Apr 2, 2017

Using the workaround for now. Thanks!

@alexsandro-xpt
Copy link

It works for me too @bricelam, Thanks!

@bricelam
Copy link
Contributor Author

Re-opening. We probably need to update the PMC tools too.

@bricelam bricelam reopened this Apr 12, 2017
@bricelam bricelam modified the milestones: 1.0.4, tools/1.0.1 Apr 12, 2017
@bricelam bricelam modified the milestones: 1.0.4, tools/1.0.1 Apr 18, 2017
@ajcvickers
Copy link
Member

@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.

@bricelam
Copy link
Contributor Author

Technically, it's in the 1.0.1 release of dotnet-ef (there is no 1.1.0).

@Eilon
Copy link
Member

Eilon commented Apr 23, 2017

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.

@ajcvickers
Copy link
Member

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!

@analogrelay
Copy link
Contributor

Verified fixed in the 1.0.1 candidate build of dotnet-ef.

@manuelmejiaio
Copy link

I just installed System.Diagnostics.DiagnosticSource and System.Collections.Immutable from the NuGet Package Manager, and everything is working :)

@obelixA
Copy link

obelixA commented May 10, 2017

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...)

@aligenc
Copy link

aligenc commented May 10, 2017

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>

@obelixA
Copy link

obelixA commented May 10, 2017

hmmm. did it for the main program and for my library that uses System.Diagnostics...
No success. I think I am missing something...

@obelixA
Copy link

obelixA commented May 10, 2017

...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 ???

@agatlin
Copy link

agatlin commented May 18, 2017

This was a great help. Thank you!

@robinchesterman
Copy link

robinchesterman commented Aug 16, 2017

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

@bricelam
Copy link
Contributor Author

@robinchesterman Have you installed the .NET Core 2.0 SDK?

@karldodd
Copy link

karldodd commented Sep 5, 2017

@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.

@smitpatel
Copy link
Member

@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.

@bruno-garcia
Copy link
Member

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.

@robinchesterman
Copy link

If I remember correctly, this issue went away when I installed .NET Core SDK 2.0.1

@karldodd
Copy link

karldodd commented Sep 19, 2017

@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.

@zahasoftware
Copy link

zahasoftware commented Dec 19, 2017

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.

@VWilcox2000
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests