You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
We need to add diagnostics mode to the linker to make it easier for the developers to track down situation where linker removes too much code (for example because of reflection).
We could add a new mode/action like linkdiag where instead of removing the methods we would rewrite the bodies to always throw an exception. It's not exactly matching the link mode output because the metadata are still there but it could help in some cases.
I've thought about adding such a feature before. I'd be curious to see how useful it is. I do think you'll have to take the results with a grain of salt. Keeping methods that would previously be removed will still have a considerable knock on effect. Ex: Parameter and return types will be marked. Interfaces will be marked. That could lead to default ctors being fully marked that would have otherwise been removed. That could ripple and cause a lot more stuff to be marked.
I've thought about adding such a feature before. I'd be curious to see how useful it is. I do think you'll have to take the results with a grain of salt. Keeping methods that would previously be removed will still have a considerable knock on effect. Ex: Parameter and return types will be marked. Interfaces will be marked. That could lead to default ctors being fully marked that would have otherwise been removed. That could ripple and cause a lot more stuff to be marked.
The CoreRT compiler has such option (dotnet/corert#6149) and it pretty much eliminated a class of issues with mysterious NullReferenceException the project was regularly getting (that were pretty much always cause by something like Type.GetMethod returning null).
CoreRT avoids the knock on effect by generating an (unresolvable) TypeReference for parameter types that wouldn't otherwise be generated. It can afford to do so because the reflection metadata is really only consumed by the reflection stack and the rest of the system doesn't care about it (everything was already done AOT).
I suspect this is going to be more complicated to pull of when dealing with real metadata that is actually used to build things like vtables and interface dispatch maps at runtime.
Hopefully with the linker warning infrastructure we're building for .NET 5, the need for this will be reduced enough that it's not necessary.
@sbomer, @MichalStrehovsky, @marek-safar do you think something like this still makes sense. Basically everything should be covered by warnings and this would only be useful when ignoring warnings.
Activity
mrvoorhe commentedon Jun 3, 2019
I've thought about adding such a feature before. I'd be curious to see how useful it is. I do think you'll have to take the results with a grain of salt. Keeping methods that would previously be removed will still have a considerable knock on effect. Ex: Parameter and return types will be marked. Interfaces will be marked. That could lead to default ctors being fully marked that would have otherwise been removed. That could ripple and cause a lot more stuff to be marked.
MichalStrehovsky commentedon Apr 1, 2020
The CoreRT compiler has such option (dotnet/corert#6149) and it pretty much eliminated a class of issues with mysterious
NullReferenceExceptionthe project was regularly getting (that were pretty much always cause by something likeType.GetMethodreturning null).CoreRT avoids the knock on effect by generating an (unresolvable)
TypeReferencefor parameter types that wouldn't otherwise be generated. It can afford to do so because the reflection metadata is really only consumed by the reflection stack and the rest of the system doesn't care about it (everything was already done AOT).I suspect this is going to be more complicated to pull of when dealing with real metadata that is actually used to build things like vtables and interface dispatch maps at runtime.
Hopefully with the linker warning infrastructure we're building for .NET 5, the need for this will be reduced enough that it's not necessary.
marek-safar commentedon Apr 1, 2020
Yeah, let's revisit this after we have the reflection warnings/errors support in.
vitek-karas commentedon Sep 12, 2022
@sbomer, @MichalStrehovsky, @marek-safar do you think something like this still makes sense. Basically everything should be covered by warnings and this would only be useful when ignoring warnings.
sbomer commentedon Sep 12, 2022
My opinion - I think with trim analysis warnings this is not needed.