How to debug Elements Mono.Cecil.SignatureWriter.WriteTypeSignature

So after finally getting the bandwidth, I’m proceeding on the great journey to migrate my infrastructure to a unified state that leverages silver for mono platforms. One such piece of this is generous with it’s usages of generics and Its one of the corner stones of my infrastructure.

I have it compiling on all platforms but its failing at the last stage of compilation with silver. I’m getting an error that only appears in the build stage:

E: Error while generating executable: System.ArgumentNullException: Value cannot be null.
  at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00004] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (Mono.Cecil.IGenericInstance instance) [0x00022] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.GetMethodSpecSignature (Mono.Cecil.MethodSpecification method_spec) [0x00027] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.CreateMethodSpecRow (Mono.Cecil.MethodSpecification method_spec) [0x00017] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.GetMethodSpecToken (Mono.Cecil.MethodSpecification method_spec) [0x00000] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.LookupToken (Mono.Cecil.IMetadataTokenProvider provider) [0x000ba] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.Cil.CodeWriter.WriteOperand (Mono.Cecil.Cil.Instruction instruction) [0x00287] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.Cil.CodeWriter.WriteInstructions () [0x00030] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x0002e] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x0002c] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00013] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00013] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x000a7] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.AddTypes () [0x00018] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00017] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.BuildModule () [0x000a2] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x0000b] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.ModuleWriter.Write (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x00106] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.ModuleWriter.WriteModule (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x00002] in <6dcf4a273260406485a54d4b20324388>:0 
  at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00017] in <6dcf4a273260406485a54d4b20324388>:0 
  at E.b (System.IO.Stream a) [0x001c3] in <c1b9d202b83345148b1cda18390f3c99>:0 

Before diving too deep into assessing any work arounds I wanted to see if I could reach out here first. Any tips on how to debug this other than to start trying to clear out and adjust some of my generic members until I find the culprit?

That’s a compiler bug, by definition. Can we see the/a project that shows this? thanx!

@mh here’s a sample project I made to illustrate these issues. I was going to try to work around it and try to rewrite the problem area but if you guys can identify the bug and fix it that would also work!

The Elements project is located under the Backends/RemObjects/Warbler directory. The Problem sources are located in the Sources/Warbler/Modules/Core/ directory.

This does compile fine on other platforms and doesn’t report any errors in the Fire editor until the final build stage.

RemObjectGenericTest.zip (823.7 KB)

For what it’s worth, the problem code is probably around the EventEmitter code. I did notice I had to extract certain inner classes that were embedded in there, outside, for me to resolve some errors being reported. Cheers!

Reproduced, thanx!

Logged as bugs://E26014.

The bug is definitely in the SingleEventEmitter source file - extension mapping function - line 46

1 Like

Thanx, thats definitely helps. That said i’m sure the team will have this narrowed down quickly once its being debugged.

At first glance my tests seem to pass without that subscribe call thats breaking…I’ll do a bit more testing but I wonder if its even necessary to account for this type of edge case. Do with it as you guys please :slight_smile:

bugs://E26014 was closed as fixed.

Definitely needed this bit to avoid more involved side effects. I’m seeing what I can do in the interim unless the resolution fixes it

i can get you a new build tomorrow.

Thank you, there is no rush. I got it working by representing the listener block as an explicit closure instead of an inlined function declaration.

1 Like