Lokad / ILPack

Serialize .NET Core assemblies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System.IndexOutOfRangeException at Save

jvbsl opened this issue · comments

commented

Void .ctor(System.String, AdvancedDLSupport.ImplementationOptions, AdvancedDLSupport.Loaders.ILibraryLoader, AdvancedDLSupport.Loaders.ISymbolLoader)

   at Lokad.ILPack.IL.MethodBodyReader.GetParameter(Int32 index)
   at Lokad.ILPack.IL.MethodBodyReader.GetVariable(Instruction instruction, Int32 index)
   at Lokad.ILPack.IL.MethodBodyReader.ReadOperand(Instruction instruction)
   at Lokad.ILPack.IL.MethodBodyReader.ReadInstructions()
   at Lokad.ILPack.IL.MethodBodyReader.GetInstructions(MethodBase method)
   at Lokad.ILPack.IL.MethodBaseExtensions.GetInstructions(MethodBase self)
   at Lokad.ILPack.IL.MethodBodyStreamWriter.AddMethodBody(MethodBase methodBase, StandaloneSignatureHandle localVariablesSignature)
   at Lokad.ILPack.AssemblyGenerator.CreateConstructor(ConstructorInfo ctor)
   at Lokad.ILPack.AssemblyGenerator.CreateConstructors(IEnumerable`1 constructors)
   at Lokad.ILPack.AssemblyGenerator.CreateType(Type type)
   at Lokad.ILPack.AssemblyGenerator.CreateTypes(IEnumerable`1 types)
   at Lokad.ILPack.AssemblyGenerator.CreateModules(IEnumerable`1 moduleInfo)
   at Lokad.ILPack.AssemblyGenerator.GenerateAssemblyBytes(Assembly assembly)
   at Lokad.ILPack.AssemblyGenerator.GenerateAssembly(Assembly assembly, String path)

It is basically about that code: https://github.com/Lokad/ILPack/blob/master/src/IL/MethodBodyReader.cs#L177
index is 0, while the ctor is not static, therefore it decrements index to the value of -1, which of course results in a IndexOutOfRangeException.

The constructor is in a sealed class and is basically a passthrough constructor to that one:
https://github.com/Firwood-Software/AdvancedDLSupport/blob/master/AdvancedDLSupport/NativeLibraryBase.cs

I don't exactly know what additional information would be helpful?

Hi @jvbsl Thanks a lot for reporting the problem to us. Looking at your example, I have identified one more problem (fixed in the commit above); however, I am not entirely sure whether I have fixed the problem that you are actually encountering.

Could you double check with the latest version of ILPack? (built from source)

commented

Unfortunately the same. Perhaps useful additional information:
"ldarg null" is the instruction which is read and passed to ReadOperand in MethodBodyReader.cs:66, where it goes through line 149, where _il.ReadInt16() reads the 0 which gets passed to GetParameter and ultimately gets decremented to -1....

@vermorel I suggest closing it for now. I'm unable to reproduce it using the provided examples and after checking the current Roslyn code I'm unable to find any place for creating the ldarg null command. In most cases, the ldarg.0 command is used for accessing the implicit this argument in the instance methods. Of course, we can add a simple check into the GetParameter method but I'm not sure how we can prepare a 'ParameterInfoobject for thethis` argument.

@OlegRa You can't reproduce. No one upvoted the issue for almost 3 years. I guess closing is reasonable at this point.