gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.19k stars 217 forks source link

ReferenceFixator fails to fix MethodReference if the method is defined on the base class. #320

Closed bucurb closed 8 months ago

bucurb commented 1 year ago

Hello,

I'm trying to merge some AspNetCore dlls. At some point, the merge tries to fix-up the references in type Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionLimitMiddleware. This type has a OnConnectionAsync method, which will at some point do connection.Features.Set..., and thus have the ReferenceFixator attempt to fix the MethodReference for Microsoft.AspNetCore.Http.Features.IFeatureCollection Microsoft.AspNetCore.Connections.ConnectionContext::get_Features().

The reference fixator will correctly go through the if (declaringType.IsDefinition && !method.IsDefinition) but fail to find a definition from MethodDefinition def = new ReflectionHelper(_repackContext).FindMethodDefinitionInType((TypeDefinition)declaringType, method);. This is because the method is not defined on the ConnectionContext class, but on its base, BaseConnectionContext. Both these classes are abstract so I don't understand why the code does not scan the inheritance hierarchy upwards when searching for a method definition, is this a bug?

KirillOsenkov commented 11 months ago

Could you please try the latest version and see if this is still a problem? https://www.nuget.org/packages/ILRepack/2.0.23

KirillOsenkov commented 11 months ago

If I'm reading this right, this should have been fixed with: https://github.com/gluck/il-repack/commit/22e076be53abe8299571607c6dedc16ff9d9c8a3

The bug was most likely: https://github.com/gluck/il-repack/issues/219