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

The package causes wrong version of 'System.Private.CoreLib' to be referenced in my app #113

Open
PandrPi opened this issue Mar 6, 2023 · 23 comments

Comments

@PandrPi
Copy link

PandrPi commented Mar 6, 2023

Hi,

I'm getting the following error when I try to debug the code of my .NET 6.0 application:

Assembly 'MyApp' with identity 'MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' which has a higher version than referenced assembly 'System.Private.CoreLib' with identity 'System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

The project named MyApp (Console application) uses .NET 6.0 as a target framework, but for some reason, MethodBoundaryAspect.Fody package causes MyApp to use System.Private.CoreLib, Version=7.0.0.0.

Yes, I'm sure that this referencing issue is caused by MethodBoundaryAspect.Fody because when I uninstall it, everything works great. With MethodBoundaryAspect.Fody included in the assembly of MyApp, the project can still be built and run without errors. Still, when I'm trying to debug the MyApp project, I cannot inspect any variables/objects, so the entire debugging process is useless, which is extremely bad for me.

Also, the issue is independent of IDE. Rider allows me to inspect variables of the current context, but only inside the Debug window and with plenty of limitations. Visual Studio doesn't allow inspecting any variables at all, and the debugger is useless. In both cases, the breakpoints worked as before. At least I didn't notice any errors related to breakpoints.

I tried to use different versions of your package, for instance, [v2.0.148], [v2.0.110], and two or three more, but there is no difference. I still get the error.

If you need any more information, please don't hesitate to let me know.

@Ralf1108
Copy link
Collaborator

Ralf1108 commented Mar 6, 2023

can you provide your examle project without reproduction steps?

@PandrPi
Copy link
Author

PandrPi commented Mar 6, 2023

Hi,
Here is a link to the example repository I've created.
https://github.com/PandrPi/FodyIssueExample

Place breakpoints as in the screenshot and then run the app in Debug mode.
image

Inspect the value of the args argument by hovering the mouse on it. You should see the following picture:
image

Also, I can inspect the object by clicking grey args: MethodExecutionArgs on the right side. It may work the same for you, but I'm not sure.
image

Also, the app prints the current referenced assemblies, which may help you figure out the root of this issue.

@PandrPi
Copy link
Author

PandrPi commented Mar 7, 2023

Hi @Ralf1108,

Is the provided information enough for you? Are you able to reproduce the issue?

@PandrPi
Copy link
Author

PandrPi commented Mar 11, 2023

Hi @Ralf1108 ,

Is there any news regarding the issue?

@Ralf1108
Copy link
Collaborator

Hi,

checking your reproduction project I can't reproduce what you observed.
Here is the output of my test run:

On entry On exit Hello, World! 863810819 Reference: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Reference: 'MethodBoundaryAspect, Version=2.0.148.0, Culture=neutral, PublicKeyToken=296379d5065c9d61' Reference: 'System.Console, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Reference: 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Reference: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

I see that you use Rider as IDE... I use Visual Studio 2022... so this could be a difference in the debugger logics.
I also saw that you use a quite old version of MBA "2.0.118". Can you retry your issues with the latest version of MBA "2.0.148" ?

@Ralf1108
Copy link
Collaborator

Ah, you already stated that you tried the latest version.

Can you retry it with Visual Studio 2022 on your machine?
I know that our debugging symbols are not best when we move the method body of the weaved method to a cloned method.
We had also commits to try to fix it but other debugging issues popped up. So maybe MSVS 2022 is more tolerant in this way.

@PandrPi
Copy link
Author

PandrPi commented Mar 14, 2023

Hi @Ralf1108,
I tried VS as well. Debugging doesn't work at all, even worse than using Rider. Do you have .Net 6 and 7 both installed on your machine? I have them both. Please, install dotnet seven and try to reproduce it again.

If there is anything I can help with, please let me know.

@Ralf1108
Copy link
Collaborator

here are my installed versions:

`C:\Users\Ralf>dotnet --list-sdks
2.2.203 [C:\Program Files\dotnet\sdk]
2.2.204 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.116 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.104 [C:\Program Files\dotnet\sdk]
5.0.214 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.202 [C:\Program Files\dotnet\sdk]
7.0.202 [C:\Program Files\dotnet\sdk]

C:\Users\Ralf>dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]`

@PandrPi
Copy link
Author

PandrPi commented Mar 15, 2023

Hello,
Here is mine:
PS C:\Users\pavlo\RiderProjects\MyApp> dotnet --list-sdks
7.0.100 [C:\Program Files\dotnet\sdk]
PS C:\Users\pavlo\RiderProjects\MyApp> dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@PandrPi
Copy link
Author

PandrPi commented Mar 15, 2023

OMG. I tried to uninstall and install the latest version of the MethodBoundaryAspect package, not from Rider but from Visual Studio, and it works great now! It looks like VS installed some extra stuff, while Rider didn't do that.

Thank you, @Ralf1108, for all your effort and your time! Please feel free to close the issue as solved!
Thank you very much!

@Ralf1108
Copy link
Collaborator

Glad that you figured this out. Maybe you can provide a diff between the different installation changes? So if something similar occurs in future we can identify the issue faster.
Thx for your effort!

@PandrPi
Copy link
Author

PandrPi commented Mar 15, 2023

@PandrPi
Copy link
Author

PandrPi commented Mar 16, 2023

Hi @Ralf1108,

The issue is not actually fixed...
Here is what the app prints when it's built with Visual Studio
image

And here is what the app prints when it's built with dotnet clean and dotnet build commands
image

Please, try to clean and build the solution with these commands, then run the app and see what it prints.

@PandrPi
Copy link
Author

PandrPi commented Mar 16, 2023

If I use C:\Users\pavlo\RiderProjects\MyApp>devenv MyApp.sln /rebuild Debug, everything works great
The problem is precisely in dotnet clean and dotnet build commands.

So you should be able to try different ways at least to build the solution.

@Ralf1108
Copy link
Collaborator

Ralf1108 commented Mar 16, 2023

wow strange.
Runnning in MSVS 2022 in Debug:
grafik

Running via "dotnet clean/build" and execute:
grafik

I think MSVS uses MSBuild and not "dotnet build". But it is rather interesting that there are different outputs.
In the build pipeline we also use "dotnet build": workflow

So.... I am a little confused what is the issue here and how to solve it 😵

@PandrPi
Copy link
Author

PandrPi commented Mar 16, 2023

I'm glad that you can reproduce the issue. It's a great step for resolving it.

@Ralf1108
Copy link
Collaborator

Ah... issue is that somehow "dotnet build" adds the reference to "System.Private.CoreLib, Version=7.0.0.0" but it shouldn't because your example project is set to "net6.0"

@PandrPi
Copy link
Author

PandrPi commented Mar 16, 2023

Yes, exactly. That's the most confusing part. But it only "works" when "MethodBoundaryAspect" is included in the assembly. When it's not included in the assembly, there is no reference to "System.Private.CoreLib" at all

@PandrPi
Copy link
Author

PandrPi commented Mar 16, 2023

I had a lot of searching and conversations with Chat GPT, and it suggested several things. For instance, to use these guys in my project file
<UseAppHost>true</UseAppHost> <RuntimeFrameworkVersion>6.0.0</RuntimeFrameworkVersion>

Install the latest version of .NET 6.0 SDK and thy the dotnet list package --include-transitive command to check if there is any reference to System.Private.CoreLib caused by any package, but it just printed me these lines:
`PS C:\Users\pavlo\RiderProjects\MyApp> dotnet list MyApp.sln package --include-transitive
Project 'MyApp' has the following package references
[net6.0]:
Top-level Package Requested Resolved

MethodBoundaryAspect.Fody 2.0.148 2.0.148

Transitive Package Resolved

Fody 6.0.5`

So, from my side, I don't have any even potential solutions to this issue. I hope you find something interesting on the web or in the package.
Thank you for all your effort.

@Ralf1108
Copy link
Collaborator

Checking the built assemblies with IL-Spy verifies the references:
grafik

@Ralf1108
Copy link
Collaborator

mscorlib seems to only contain TypeForwards
grafik

@Ralf1108
Copy link
Collaborator

Interesting... the assembly built with MSVS doesn't resolve the "System.Private.CoreLib".
But in the above screenshots in the "dotnet" build version 7.0.0.0 of "System.Private.CoreLib" is referenced.
Strange if this reference is clicked for the first time ILSpy automatically loads the assembly with version 6.0.0.0 "System.Private.CoreLib".
grafik

@Ralf1108
Copy link
Collaborator

Now thats really strange.
grafik

If I check the corresponding file "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.4\System.Private.CoreLib.dl" and check the details it says that it is version 6.0.0.0:
grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants