gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.16k stars 214 forks source link

Can not use protobuf-net with ILRepack #329

Closed dimsa closed 8 months ago

dimsa commented 9 months ago

I try to merge libraries into one file using ILRepack

ILRepack.exe /union /out:repack.dll"ProbufRepack.dll" "System.Collections.Immutable.dll" "protobuf-net.Core.dll" "protobuf-net.dll"

And get the following error:

Mono.Cecil.ResolutionException: Failed to resolve System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
   at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
   at Mono.Cecil.MetadataBuilder.AddField(FieldDefinition field)
   at Mono.Cecil.MetadataBuilder.AddFields(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypeDefs()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
   at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at ILRepacking.ILRepack.Repack()
   at ILRepacking.Application.Main(String[] args)

Please find attached simple project to reproduce it. ILRepack and all libraries can be found in bin/Release/net6.0 Protobuf and ILRepack have last versions.

ProbufRepack.zip

I also tried to download sources of Probuf-net.Core, I've found this types, but was not able to change this behavior.

Please also check the protobuf sources: https://github.com/protobuf-net/protobuf-net/blob/main/src/protobuf-net.Core/Internal/DynamicallyAccessedMembersAttribute.cs. Protobuf hasn't nuget dependency with these types.

Thank you in advance.

KirillOsenkov commented 8 months ago

Confirmed that 2.0.23 is broken, but latest master is fixed. We will publish 2.0.24 soon and it should be fixed there.