nooogle / CDS.CSharpScripting

Drop-in user control for C# editing with intellisense and compilation. Script compilation and execution classes for GUI and console applications.
MIT License
9 stars 3 forks source link

ReflectionTypeLoadException - Microsoft.CodeAnalysis #31

Open tcartwright opened 2 years ago

tcartwright commented 2 years ago

I am getting the below error when calling CDS.CSharpScripting.CodeEditor.CDSInitialize. I have confirmed that I am indeed not passing in a type from the code analysis library. Yet I cannot get rid of this exception. My project references this library, but it is not in the list of types passed into the initialize method.

System.Reflection.ReflectionTypeLoadException
  HResult=0x80131602
  Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  Source=mscorlib
  StackTrace:
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeAssembly.get_DefinedTypes()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
   at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
   at RoslynPad.Roslyn.RoslynHost..ctor(IEnumerable`1 additionalAssemblies, RoslynHostReferences references, Nullable`1 disabledDiagnostics)
   at CDS.CSharpScripting.CodeEditor.CreateRosylnHost(Type globalsType, List`1 referenceTypesIncludingGlobalsType, List`1 namespaceTypesIncludingGlobalsType)
   at CDS.CSharpScripting.CodeEditor.CDSInitialize(IEnumerable`1 namespaceTypes, IEnumerable`1 referenceTypes, Type globalsType)

-       LoaderExceptions    {System.Exception[17]}  System.Exception[]
+       [0] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationArrayTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationArrayTypeSymbol"}    System.Exception {System.TypeLoadException}
+       [1] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedMethodSymbol"}    System.Exception {System.TypeLoadException}
+       [2] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedNamedTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedNamedTypeSymbol"}  System.Exception {System.TypeLoadException}
+       [3] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"}  System.Exception {System.TypeLoadException}
+       [4] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"}  System.Exception {System.TypeLoadException}
+       [5] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"}  System.Exception {System.TypeLoadException}
+       [6] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationEventSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationEventSymbol"}    System.Exception {System.TypeLoadException}
+       [7] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationFieldSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationFieldSymbol"}    System.Exception {System.TypeLoadException}
+       [8] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"}  System.Exception {System.TypeLoadException}
+       [9] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamedTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamedTypeSymbol"}    System.Exception {System.TypeLoadException}
+       [10] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamespaceSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamespaceSymbol"}   System.Exception {System.TypeLoadException}
+       [11] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"} System.Exception {System.TypeLoadException}
+       [12] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol"}   System.Exception {System.TypeLoadException}
+       [13] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPointerTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPointerTypeSymbol"}   System.Exception {System.TypeLoadException}
+       [14] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPropertySymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPropertySymbol"} System.Exception {System.TypeLoadException}
+       [15] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationTypeParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationTypeParameterSymbol"}   System.Exception {System.TypeLoadException}
+       [16] {"Method 'get_GlobalOptions' in type 'WorkspaceAnalyzerConfigOptionsProvider' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"WorkspaceAnalyzerConfigOptionsProvider"} System.Exception {System.TypeLoadException}
nooogle commented 2 years ago

Hi - from my own experience, this kind of problem happens after I’ve used NuGet to update to the latest packages.

I think that my library, and the libraries I reference via NuGet for the editor, are all based on the 3.6.0 version of many of the Microsoft scripting libraries.

Perhaps you’re bringing in a newer library, or a library that has dependencies on a new version of one of these libraries?

You could also try cloning my solution directly and verifying that the solution builds and the demos run ok. Then try introducing some of your references into one of the demos to see if there’s a point at which it breaks.

Hope this might help.

FYI I’m working on a new version of

Thanks, Jon

㊔ Carpe Diem Systems Limited

Registered in England & Wales: 3268509

🏠 14 Lawley Way, Droitwich, WR9 8FB 🕸️ http://www.carpediemsystems.co.uk/ http://www.carpediemsystems.co.uk/ 📧 @. @.> ☎️ +44 (0) 7545 533911

On 16 Jun 2022, at 00:35, Tim Cartwright @.***> wrote:

I am getting the below error when calling CDS.CSharpScripting.CodeEditor.CDSInitialize. I have confirmed that I am indeed not passing in a type from the code analysis library. Yet I cannot get rid of this exception. My project references this library, but it is not in the list of types passed into the initialize method.

System.Reflection.ReflectionTypeLoadException HResult=0x80131602 Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. Source=mscorlib StackTrace: at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeAssembly.get_DefinedTypes() at System.Linq.Enumerable.d__172.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable1 types, AttributedModelProvider attributeContext) at System.Composition.Hosting.ContainerConfiguration.CreateContainer() at RoslynPad.Roslyn.RoslynHost..ctor(IEnumerable1 additionalAssemblies, RoslynHostReferences references, Nullable1 disabledDiagnostics) at CDS.CSharpScripting.CodeEditor.CreateRosylnHost(Type globalsType, List1 referenceTypesIncludingGlobalsType, List1 namespaceTypesIncludingGlobalsType) at CDS.CSharpScripting.CodeEditor.CDSInitialize(IEnumerable1 namespaceTypes, IEnumerable`1 referenceTypes, Type globalsType)

  • LoaderExceptions {System.Exception[17]} System.Exception[]
  • [0] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationArrayTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationArrayTypeSymbol"} System.Exception {System.TypeLoadException}
  • [1] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedMethodSymbol"} System.Exception {System.TypeLoadException}
  • [2] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedNamedTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationConstructedNamedTypeSymbol"} System.Exception {System.TypeLoadException}
  • [3] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"} System.Exception {System.TypeLoadException}
  • [4] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"} System.Exception {System.TypeLoadException}
  • [5] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"} System.Exception {System.TypeLoadException}
  • [6] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationEventSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationEventSymbol"} System.Exception {System.TypeLoadException}
  • [7] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationFieldSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationFieldSymbol"} System.Exception {System.TypeLoadException}
  • [8] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"} System.Exception {System.TypeLoadException}
  • [9] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamedTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamedTypeSymbol"} System.Exception {System.TypeLoadException}
  • [10] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamespaceSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationNamespaceSymbol"} System.Exception {System.TypeLoadException}
  • [11] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol"} System.Exception {System.TypeLoadException}
  • [12] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol"} System.Exception {System.TypeLoadException}
  • [13] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPointerTypeSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPointerTypeSymbol"} System.Exception {System.TypeLoadException}
  • [14] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPropertySymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationPropertySymbol"} System.Exception {System.TypeLoadException}
  • [15] {"Method 'get_MetadataToken' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationTypeParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationTypeParameterSymbol"} System.Exception {System.TypeLoadException}
  • [16] {"Method 'get_GlobalOptions' in type 'WorkspaceAnalyzerConfigOptionsProvider' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.":"WorkspaceAnalyzerConfigOptionsProvider"} System.Exception {System.TypeLoadException} — Reply to this email directly, view it on GitHub https://github.com/nooogle/CDS.CSharpScripting/issues/31, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADE2TGIMMWR4LSDRPHMHXN3VPJSD3ANCNFSM5Y47A3JA. You are receiving this because you are subscribed to this thread.