Description
We work around dotnet/runtime#131892 (the trimmer crashes with a NullReferenceException, surfaced as error IL1012, when it computes the documentation signature of a method whose parameter type is a nested type from another assembly) by emitting [DynamicDependency] signatures without a parameter list whenever the method name (+ generic arity) is unambiguous within its declaring type.
The trimmer then matches the method by name and arity alone, so it never has to compute a parameter signature — and never crashes.
Once the trimmer bug is fixed (and we've moved to a version of the SDK that contains the fix), this workaround should be removed so that [DynamicDependency] attributes are precise again instead of preserving every overload.
Steps to reproduce
See dotnet/runtime#131892 for a self-contained repro.
What needs to be done
| Location |
What to do |
tools/dotnet-linker/AppBundleRewriter.cs |
Remove GetDynamicDependencySignature and go back to calling DocumentationComments.GetSignature directly in AddDynamicDependencyAttribute and AddDynamicDependencyAttributeToStaticConstructor. |
tools/dotnet-linker/DocumentionComments.cs |
Remove GetNameSignature if it ends up with no callers. |
tests/assembly-preparer/PreserveBlockCodeHandlerTests.cs |
Restore the Invoke(System.IntPtr,System.Int32) expectation. |
tests/assembly-preparer/PreserveSmartEnumConversionsTest.cs |
Restore the GetConstant(CoreAnimation.CAToneMapMode) expectation. |
tests/dotnet/UnitTests/expected/* |
Regenerate the expected app sizes (precise signatures preserve fewer members). |
Note that AddPreserveAllMembersDynamicDependencyAttributes also uses GetNameSignature, but that one is intentional and should stay: it implements [Preserve (AllMembers = true)], where every overload is preserved anyway, so matching by name is both correct and cheaper.
Context
The workaround was added in #26410.
Description
We work around dotnet/runtime#131892 (the trimmer crashes with a
NullReferenceException, surfaced aserror IL1012, when it computes the documentation signature of a method whose parameter type is a nested type from another assembly) by emitting[DynamicDependency]signatures without a parameter list whenever the method name (+ generic arity) is unambiguous within its declaring type.The trimmer then matches the method by name and arity alone, so it never has to compute a parameter signature — and never crashes.
Once the trimmer bug is fixed (and we've moved to a version of the SDK that contains the fix), this workaround should be removed so that
[DynamicDependency]attributes are precise again instead of preserving every overload.Steps to reproduce
See dotnet/runtime#131892 for a self-contained repro.
What needs to be done
tools/dotnet-linker/AppBundleRewriter.csGetDynamicDependencySignatureand go back to callingDocumentationComments.GetSignaturedirectly inAddDynamicDependencyAttributeandAddDynamicDependencyAttributeToStaticConstructor.tools/dotnet-linker/DocumentionComments.csGetNameSignatureif it ends up with no callers.tests/assembly-preparer/PreserveBlockCodeHandlerTests.csInvoke(System.IntPtr,System.Int32)expectation.tests/assembly-preparer/PreserveSmartEnumConversionsTest.csGetConstant(CoreAnimation.CAToneMapMode)expectation.tests/dotnet/UnitTests/expected/*Note that
AddPreserveAllMembersDynamicDependencyAttributesalso usesGetNameSignature, but that one is intentional and should stay: it implements[Preserve (AllMembers = true)], where every overload is preserved anyway, so matching by name is both correct and cheaper.Context
The workaround was added in #26410.