Bug 35310

Summary: Roslyn Crashes to a bug in equality comparer
Product: [Mono] Class Libraries Reporter: Dylan Borg <borgdylan>
Component: mscorlibAssignee: Rodrigo Kumpera <kumpera>
Status: RESOLVED FIXED    
Severity: normal CC: borgdylan, kumpera, mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description Dylan Borg 2015-10-27 16:17:16 UTC
While running roslyn as part of the latest bleeding edge DNX using mono from the master git branch I get an InvalidCastException as follows. Does mono/.NET generate equality comparers via dynamic code gen? The ShortEnumEqualityComparer seems to be buggy and I can't find it in any dll I have have looked at both mono and roslyn.

Error: Specified cast is not valid.
Error: Full Exception: System.InvalidCastException: Specified cast is not valid.
  at System.Collections.Generic.ShortEnumEqualityComparer`1[T].GetHashCode (T obj) <0xb2948230 + 0x0003c> in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) [0x00023] in /mnt/ssd/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:326 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) [0x00000] in /mnt/ssd/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:187 
  at Microsoft.CodeAnalysis.Collections.OrderPreservingMultiDictionary`2[K,V].Add (Microsoft.CodeAnalysis.Collections.K k, Microsoft.CodeAnalysis.Collections.V v) <0xb2947408 + 0x001b7> in <filename unknown>:0 
  at Microsoft.Cci.MetadataWriter.PopulateDeclSecurityTableRowsFor (UInt32 parent, IEnumerable`1 attributes) <0xb2946f90 + 0x000a7> in <filename unknown>:0 
  at Microsoft.Cci.MetadataWriter.PopulateDeclSecurityTableRows () <0xb2946d40 + 0x00057> in <filename unknown>:0 
  at Microsoft.Cci.MetadataWriter.PopulateTables (System.Int32[] methodBodyRvas, Microsoft.Cci.BlobBuilder mappedFieldDataWriter, Microsoft.Cci.BlobBuilder resourceWriter) <0xb2944fd8 + 0x00033> in <filename unknown>:0 
  at Microsoft.Cci.MetadataWriter.SerializeMetadataAndIL (Microsoft.Cci.BlobBuilder metadataWriter, Microsoft.Cci.BlobBuilder debugMetadataWriterOpt, Microsoft.Cci.PdbWriter nativePdbWriterOpt, Microsoft.Cci.BlobBuilder ilWriter, Microsoft.Cci.BlobBuilder mappedFieldDataWriter, Microsoft.Cci.BlobBuilder managedResourceDataWriter, Int32 methodBodyStreamRva, System.Func`2 calculateMappedFieldDataStreamRva, System.Int32& moduleVersionIdOffsetInMetadataStream, System.Int32& pdbIdOffsetInPortablePdbStream, System.Int32& entryPointToken, Microsoft.Cci.MetadataSizes& metadataSizes) <0xb2964840 + 0x00097> in <filename unknown>:0 
  at Microsoft.Cci.PeWriter.WritePeToStream (Microsoft.Cci.MetadataWriter mdWriter, System.Func`1 getPeStream, System.Func`1 getPortablePdbStreamOpt, Microsoft.Cci.PdbWriter nativePdbWriterOpt) <0xb29636e8 + 0x00467> in <filename unknown>:0 
  at Microsoft.Cci.PeWriter.WritePeToStream (EmitContext context, Microsoft.CodeAnalysis.CommonMessageProvider messageProvider, System.Func`1 getPeStream, System.Func`1 getPortablePdbStreamOpt, Microsoft.Cci.PdbWriter nativePdbWriterOpt, System.String pdbPathOpt, Boolean allowMissingMethodBodies, Boolean deterministic, CancellationToken cancellationToken) <0xb295cfb0 + 0x00133> in <filename unknown>:0 
  at Microsoft.CodeAnalysis.Compilation.SerializeToPeStream (Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder moduleBeingBuilt, Microsoft.CodeAnalysis.EmitStreamProvider peStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider pdbStreamProvider, System.Func`1 testSymWriterFactory, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Boolean metadataOnly, CancellationToken cancellationToken) <0xb295c000 + 0x00603> in <filename unknown>:0 
  at Microsoft.CodeAnalysis.Compilation.Emit (Microsoft.CodeAnalysis.EmitStreamProvider peStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider pdbStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider xmlDocumentationStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider win32ResourcesStreamProvider, IEnumerable`1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, IMethodSymbol debugEntryPoint, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Func`1 getHostDiagnostics, CancellationToken cancellationToken) <0xb325b110 + 0x0047f> in <filename unknown>:0 
  at Microsoft.CodeAnalysis.Compilation.Emit (System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, IEnumerable`1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, IMethodSymbol debugEntryPoint, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Func`1 getHostDiagnostics, CancellationToken cancellationToken) <0xb325af60 + 0x00187> in <filename unknown>:0 
  at Microsoft.CodeAnalysis.Compilation.Emit (System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, IEnumerable`1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, IMethodSymbol debugEntryPoint, CancellationToken cancellationToken) <0xb325ade8 + 0x0008f> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.CSharp.RoslynProjectReference.Load (System.Reflection.AssemblyName assemblyName, IAssemblyLoadContext loadContext) <0xb3257890 + 0x00403> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.CompilationEngine.LoadProject (Microsoft.Dnx.Runtime.Project project, System.Runtime.Versioning.FrameworkName targetFramework, System.String aspect, IAssemblyLoadContext loadContext, System.Reflection.AssemblyName assemblyName) <0xb3257260 + 0x000f6> in <filename unknown>:0 
  at Microsoft.Dnx.Runtime.Loader.ProjectAssemblyLoader.Load (System.Reflection.AssemblyName assemblyName, IAssemblyLoadContext loadContext) <0xb3256e20 + 0x0015b> in <filename unknown>:0 
  at Microsoft.Dnx.Runtime.Loader.RuntimeLoadContext.LoadWithoutDefault (System.Reflection.AssemblyName assemblyName) <0xb3256db0 + 0x00023> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.BuildLoadContext.Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContext.Load (System.Reflection.AssemblyName assemblyName) <0xb4028750 + 0x00057> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.CSharp.RoslynCompiler+<>c__DisplayClass11_0.<GetCompileModules>b__0 (Microsoft.Dnx.Compilation.Caching.CacheContext _) <0xb3253118 + 0x000c2> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.Caching.CacheExtensions+<>c__DisplayClass0_0`1[T].<Get>b__0 (Microsoft.Dnx.Compilation.Caching.CacheContext ctx) <0xb406b938 + 0x0001b> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.Caching.Cache.CreateEntry (System.Object k, System.Func`2 acquire) <0xb406b6e8 + 0x00111> in <filename unknown>:0 
  at Microsoft.Dnx.Compilation.Caching.Cache+<>c__DisplayClass5_0.<AddEntry>b__0 () <0xb406b680 + 0x00023> in <filename unknown>:0 
  at System.Lazy`1[T].CreateValue () <0xb515fad0 + 0x00189> in <filename unknown>:0
Comment 1 Rodrigo Kumpera 2015-11-09 22:22:39 UTC
Possible fix: https://github.com/mono/mono/pull/2213
Comment 2 Rodrigo Kumpera 2015-11-12 16:15:51 UTC
Fixed.