-
Notifications
You must be signed in to change notification settings - Fork 128
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
Linker doesn't preserve type forwarder for a nested type in a second type forwarder #2359
Comments
The actual problem is that setup like this, the project trims the assemblies as a mix of "copy" and "copyused" actions. This is bound to break. "copyused" makes the assumption that all type refs are rewritten to point to implementation assembly (as it doesn't preserve type forwarders by default and it doesn't mark them). On the other hand "copy" can't rewrite the type refs. The workaround is to set |
This looks to me like something worth servicing fix, thought? |
I don't think this is worth servicing. I honestly even question if we should fix it. Going forward we don't want people to use "copyused". It's not the default anymore, the only way to get there is through As for this specific issue - as far as I can tell, type forwarders were always problematic. It's just that .NET 6 behaves differently from .NET 5, but they're both wrong in certain cases. I guess it's a discussion of importance - how important is it to make it work, given it's not the default and we generally don't encourage people to use it. |
ok, I missed there is custom setting of
Should we start issuing a warning about this mode in .NET7 so we can remove it in .NET8? |
The problematic scenario is if there's a "copy" assembly with a forwarder to a "link" assembly with a forwarder. The forwarder is for a nested class. Test for dotnet#2359. Also improved the test infra to print out errors from ilasm if they happen.
This is actually a bug for "link" mode as well. The scenario is:
Trimming this setup will actually remove one of the nested type forwarders in the
The bug exists both in "copyused" and "link" modes. |
Test for this issue in the linker is #2372. Note that fixing the problem in linker doesn't depend on the Cecil fix. The Cecil bug just makes it so that the bug in the linker doesn't cause failures. If the linker creates a correct type ref with declaring type set, it will work even on current cecil correctly. |
…otnet#2372) The problematic scenario is if there's a "copy" assembly with a forwarder to a "link" assembly with a forwarder. The forwarder is for a nested class. Test for dotnet#2359. Also improved the test infra to print out errors from ilasm if they happen.
The fix for this has been merged into the 6.0.2xx branch and should appear in 6.0.200 SDK soon. |
…otnet/linker#2372) The problematic scenario is if there's a "copy" assembly with a forwarder to a "link" assembly with a forwarder. The forwarder is for a nested class. Test for dotnet/linker#2359. Also improved the test infra to print out errors from ilasm if they happen. Commit migrated from dotnet/linker@57574f1
…otnet/linker#2372) The problematic scenario is if there's a "copy" assembly with a forwarder to a "link" assembly with a forwarder. The forwarder is for a nested class. Test for dotnet/linker#2359. Also improved the test infra to print out errors from ilasm if they happen. Commit migrated from dotnet/linker@70cd7ed
Repro:
app.csproj
app.cs
Publish the app with trimming enabled and run it. It fails with
Could not load type 'Enumerator' from assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
The reason is that
Azure.ResourceManager.dll
has a type reference to aSystem.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable``1/Enumerator
inMicrosoft.Bcl.AsyncInterfaces
. This assembly has a type forwarder for this nested type which points tonetstandard
. Andnetstandard
has a type forward to corelib.After trimming only the type forwarder in
Microsoft.Bcl.AsyncInterfaces
is kept. The one innetstandard
is removed. Note that the parent type is kept in both cases, it's only the nested type forwarder which is removed.Also notes that this runs the linker in copyused mode.
The text was updated successfully, but these errors were encountered: