尝试调试发出错误,是否有一种简单的方法可以找到有关由发出的代码引起的异常 c 的更多信息?
例如,使用以下代码:
let dynamicAssembly =
let asmName = new AssemblyName("MyAsm")
let asmBuilder = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run)
let moduleBuilder = asmBuilder.DefineDynamicModule("MyModule")
let typeBuilder = moduleBuilder.DefineType("MyDynamicType")
let methodBuilder =
let build = typeBuilder.DefineMethod("MyMethod", MethodAttributes.Public,
CallingConventions.Standard,
typeof<Int32>,
[|typeof<Int32>; typeof<Int32>|])
let ilGen = build.GetILGenerator()
ilGen.Emit(OpCodes.Ldarg_0)
ilGen.Emit(OpCodes.Ldarg_1)
ilGen.Emit(OpCodes.Add)
ilGen.Emit(OpCodes.Ret)
typeBuilder.CreateType() |> ignore
asmBuilder
let myType = dynamicAssembly.GetType("MyDynamicType")
let myObj = Activator.CreateInstance(myType)
myObj.GetType().GetMethod("MyMethod").Invoke(myObj, [|2; 3|]) |> ignore
当我尝试在倒数第二行调用时,我得到“调用的目标已引发异常Invoke
。发出代码一直是有问题的,但如果我能弄清楚如何获得有意义的异常,它可能会不那么痛苦. 想法?