gluck / il-repack

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

InvalidCastException when trying to merge Oracle.ManagedDataAccess.dll #319

Closed javeiga-iest closed 7 months ago

javeiga-iest commented 1 year ago

Using ILRepack 2.0.18 and trying to merge Oracle.ManagedDataAccess.dll returns the following error:

1>  System.InvalidCastException: No se puede convertir un objeto de tipo 'System.SByte' al tipo 'System.String'.
1>     en Mono.Cecil.MetadataBuilder.GetConstantSignature(ElementType type, Object value)
1>     en Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
1>     en Mono.Cecil.MetadataBuilder.AddField(FieldDefinition field)
1>     en Mono.Cecil.MetadataBuilder.AddFields(TypeDefinition type)
1>     en Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
1>     en Mono.Cecil.MetadataBuilder.AddTypeDefs()
1>     en Mono.Cecil.MetadataBuilder.BuildTypes()
1>     en Mono.Cecil.MetadataBuilder.BuildModule()
1>     en Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
1>     en Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
1>     en Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
1>     en ILRepacking.ILRepack.Repack()
1>     en ILRepacking.Application.Main(String[] args)

This works fine if we use the Oracle.ManagedDataAccess.dll v 19.18.0. All versions after that one returns System.InvalidCastException.

Any idea how to fix it?

KirillOsenkov commented 11 months ago

Could you please try the latest ILRepack version: https://www.nuget.org/packages/ILRepack/2.0.23

DavidHess-ITS commented 8 months ago

I am using ILRepack.LIB.MSBuild.Task 2.0.29 and i get this same error with latest Oracle.ManagedDataAccess.dll (21.13.0):

packages\ILRepack.Lib.MSBuild.Task.2.0.29\build\ILRepack.Lib.MSBuild.Task.targets(16,9): error : Unable to cast object of type 'System.SByte' to type 'System.String'.

KirillOsenkov commented 7 months ago

The Oracle assembly is obfuscated. There's a field a::b of type string that has an sbyte constant 32:

image

KirillOsenkov commented 7 months ago

Not sure if we want to support this case, but if we do, we're going to have to patch Cecil.

DavidHess-ITS commented 7 months ago

Not sure if we want to support this case, but if we do, we're going to have to patch Cecil.

For my part, I would encourage that you try to support it. We can't always control the third party assemplies we want to merge.

Can you suggest where in the Cecil code the is? Maybe that isn't obvious yet.

KirillOsenkov commented 7 months ago

It's in the stack above: Mono.Cecil.MetadataBuilder.GetConstantSignature

Cecil needs to roundtrip any assembly as is, preserving the exact bytes

Fortunately we already have a fork of Cecil, so if we do make a fix in Cecil it'll be easier

DavidHess-ITS commented 7 months ago

I have a patch for Cecil, i guess i should go to that repo and submit?

KirillOsenkov commented 7 months ago

nope, we have a submodule: image

You can send a PR against this branch of my fork: https://github.com/KirillOsenkov/cecil/tree/ilrepack

DavidHess-ITS commented 7 months ago

PR created. I created a test for my change, and I don't think it breaks anything else, but I am not familiar with this codebase so...

Thanks for considering it!

KirillOsenkov commented 7 months ago

Now need to bump the cecil submodule to the latest commit in the ilrepack branch

KirillOsenkov commented 7 months ago

done, this should be included in the next release

KirillOsenkov commented 7 months ago

Fixed in 2.0.31: https://github.com/gluck/il-repack/releases/tag/2.0.31