Unable to generate method body?
nickbclifford opened this issue · comments
I just started using ILPack in a repository of mine, but as soon as I tried to generate an assembly, I started to get this error:
System.Collections.Generic.KeyNotFoundException: The given key 'System.Type GetType()' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Lokad.ILPack.IL.MethodBodyWriter.Write(BlobBuilder writer, IReadOnlyList`1 il, Func`2 getString, IReadOnlyDictionary`2 typeHandles, IReadOnlyDictionary`2 ctorRefHandles, IReadOnlyDictionary`2 fieldHandles, IReadOnlyDictionary`2 methodHandles)
at Lokad.ILPack.IL.MethodBodyStreamWriter.AddMethodBody(MethodBase methodBase)
at Lokad.ILPack.AssemblyGenerator.GetOrCreateMethod(MethodInfo methodInfo)
at Lokad.ILPack.AssemblyGenerator.CreateMethods(MethodInfo[] methods)
at Lokad.ILPack.AssemblyGenerator.GetOrCreateType(Type type)
at Lokad.ILPack.AssemblyGenerator.CreateTypes(Type[] types)
at Lokad.ILPack.AssemblyGenerator.CreateModules(Module[] moduleInfo)
at Lokad.ILPack.AssemblyGenerator.GenerateAssemblyBytes(Assembly assembly)
at Lokad.ILPack.AssemblyGenerator.GenerateAssembly(Assembly assembly, String path)
at Broccoli.CauliflowerInterpreter.<>c.<.cctor>b__48_19(Interpreter cauliflower, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/CauliflowerBuiltins.cs:line 1381
at Broccoli.ShortCircuitFunction.Invoke(Interpreter broccoli, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/Function.cs:line 101
at Broccoli.CauliflowerInterpreter.<>c.<.cctor>b__48_1(Interpreter cauliflower, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/CauliflowerBuiltins.cs:line 402
at Broccoli.ShortCircuitFunction.Invoke(Interpreter broccoli, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/Function.cs:line 101
at Broccoli.CauliflowerInterpreter.Run(IValueExpressible expr) in /home/nick/Desktop/broccoli/Broccoli/Cauliflower.cs:line 52
at Broccoli.CauliflowerInterpreter.Run(ParseNode node) in /home/nick/Desktop/broccoli/Broccoli/Cauliflower.cs:line 31
at Broccoli.Program.Main(String[] args) in /home/nick/Desktop/broccoli/Broccoli/Program.cs:line 80
After stepping through with a debugger and whatnot, I figured out that the error is happening when it tries to generate the body for this method, specifically the object#GetType()
call.
This should be addressed in #31 commit which is currently under review.
Hi @nickbclifford Thanks a lot for your follow-up. I have merged the latest fixes from @osman-turan. Could you give another try to see if the latest version works for you now? Thanks!
@vermorel That did get rid of the specific error I was having before, although now I'm having a new error:
System.ArgumentNullException: Value cannot be null.
Parameter name: value
at System.Reflection.Throw.ArgumentNull(String parameterName)
at System.Reflection.Metadata.Ecma335.MetadataBuilder.GetOrAddString(String value)
at Lokad.ILPack.Metadata.AssemblyMetadata.GetOrAddString(String value)
at Lokad.ILPack.AssemblyGenerator.ReserveTypeDefinition(Type type, TypeDefinitionMetadataOffset offset)
at Lokad.ILPack.AssemblyGenerator.ReserveTypes(IEnumerable`1 types)
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)
at Broccoli.CauliflowerInterpreter.<>c.<.cctor>b__48_19(Interpreter cauliflower, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/CauliflowerBuiltins.cs:line 1381
at Broccoli.ShortCircuitFunction.Invoke(Interpreter broccoli, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/Function.cs:line 101
at Broccoli.CauliflowerInterpreter.<>c.<.cctor>b__48_1(Interpreter cauliflower, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/CauliflowerBuiltins.cs:line 402
at Broccoli.ShortCircuitFunction.Invoke(Interpreter broccoli, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/Function.cs:line 101
at Broccoli.CauliflowerInterpreter.Run(IValueExpressible expr) in /home/nick/Desktop/broccoli/Broccoli/Cauliflower.cs:line 52
at Broccoli.CauliflowerInterpreter.Run(ParseNode node) in /home/nick/Desktop/broccoli/Broccoli/Cauliflower.cs:line 31
at Broccoli.Program.Main(String[] args) in /home/nick/Desktop/broccoli/Broccoli/Program.cs:line 80
I didn't bother stepping into the debugger with this one, so I'm not totally sure where this is coming from.
@nickbclifford Thank you for providing stack trace. Now, null strings are supported via #35 (and merged into master). So, it should cover your case.
@osman-turan @vermorel That fixed the null argument error, but I'm still getting an error. It seems quite different to the other ones I've been getting, but I know that the IL that I'm emitting successfully runs, so it must be something to do with ILPack's internals.
System.InvalidOperationException: Constructor cannot be found: Void .ctor(System.Object)
at Lokad.ILPack.Metadata.AssemblyMetadata.GetConstructorHandle(ConstructorInfo ctor)
at Lokad.ILPack.IL.MethodBodyWriter.Write(IAssemblyMetadata metadata, IReadOnlyList`1 il)
at Lokad.ILPack.IL.MethodBodyStreamWriter.AddMethodBody(MethodBase methodBase)
at Lokad.ILPack.AssemblyGenerator.CreateMethod(MethodInfo method)
at Lokad.ILPack.AssemblyGenerator.CreateMethods(IEnumerable`1 methods)
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)
at Broccoli.CauliflowerInterpreter.<>c.<.cctor>b__48_19(Interpreter cauliflower, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/CauliflowerBuiltins.cs:line 1327
at Broccoli.ShortCircuitFunction.Invoke(Interpreter broccoli, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/Function.cs:line 101
at Broccoli.CauliflowerInterpreter.<>c.<.cctor>b__48_1(Interpreter cauliflower, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/CauliflowerBuiltins.cs:line 404
at Broccoli.ShortCircuitFunction.Invoke(Interpreter broccoli, IValueExpressible[] args) in /home/nick/Desktop/broccoli/Broccoli/Function.cs:line 101
at Broccoli.CauliflowerInterpreter.Run(IValueExpressible expr) in /home/nick/Desktop/broccoli/Broccoli/Cauliflower.cs:line 52
at Broccoli.CauliflowerInterpreter.Run(ParseNode node) in /home/nick/Desktop/broccoli/Broccoli/Cauliflower.cs:line 31
at Broccoli.Program.Main(String[] args) in /home/nick/Desktop/broccoli/Broccoli/Program.cs:line 80
This issue is now resolved for me when using a DLL built from the develop
branch.
Thanks @nickbclifford for quick feedback. I'm glad it's finally resolved 🙂 Usually develop
branch reviews are completed within 1-3 business days. So, please check back master
branch after this time for a possible tweak.