C
C#5mo ago
thegu5

Debugging a ReflectionTypeLoadException

I'm using a tool called Cpp2IL to generate types like this in assemblies:
c#
// Cpp2IlInjected.WasmMethod.WasmMethod
using System;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class WasmMethod : Attribute
{
public int Index;
}
c#
// Cpp2IlInjected.WasmMethod.WasmMethod
using System;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class WasmMethod : Attribute
{
public int Index;
}
(il:)
.class public auto ansi sealed Cpp2IlInjected.WasmMethod.WasmMethod
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = (
01 00 40 00 00 00 01 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00
)
// Fields
.field public int32 Index

// Methods
.method public specialname rtspecialname
instance void .cctor () cil managed
{
// Method begins at RVA 0x8d77
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8

IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method WasmMethod::.cctor

} // end of class Cpp2IlInjected.WasmMethod.WasmMethod
.class public auto ansi sealed Cpp2IlInjected.WasmMethod.WasmMethod
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = (
01 00 40 00 00 00 01 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00
)
// Fields
.field public int32 Index

// Methods
.method public specialname rtspecialname
instance void .cctor () cil managed
{
// Method begins at RVA 0x8d77
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8

IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method WasmMethod::.cctor

} // end of class Cpp2IlInjected.WasmMethod.WasmMethod
everything looks valid after comparing it to output from https://sharplab.io - so, are there any ways I continue debugging this to figure out what went wrong with generation? (/is there anything incorrect that stands out?)
SharpLab
C#/VB/F# compiler playground.
2 Replies
thegu5
thegu55mo ago
stack trace
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Cpp2IlInjected.WasmMethod' from assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at Program.<Main>$(String[] args) in /home/gu5/RiderProjects/Il2CppWasmBindgen/Program.cs:line 76
System.TypeLoadException: Could not load type 'Cpp2IlInjected.WasmMethod' from assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Cpp2IlInjected.WasmMethod' from assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at Program.<Main>$(String[] args) in /home/gu5/RiderProjects/Il2CppWasmBindgen/Program.cs:line 76
System.TypeLoadException: Could not load type 'Cpp2IlInjected.WasmMethod' from assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
MODiX
MODiX5mo ago
Please don't upload any potentially harmful files @thegu5, your message has been removed
Want results from more Discord servers?
Add your server