如何使用mono.cecil注入HTTP调用

问题描述

我正在尝试使用mono cecil推送HTTP调用,但在校准时出现问题 C#中的实际代码:

var res = client.GetAsync(urlParameters);

使用https://cecilifier.me/

进行了转换
    var lv_res32 = new VariableDefinition(assembly.MainModule.ImportReference(typeof(System.Threading.Tasks.Task)));
    CodeInsight_WorkThreadFunction_.Body.Variables.Add(lv_res32);
    var Ldloc33 = il_CodeInsight_WorkThreadFunction_.Create(OpCodes.Ldloc,lv_client13);
    il_CodeInsight_WorkThreadFunction_.Append(Ldloc33);
    var Callvirt34 = il_CodeInsight_WorkThreadFunction_.Create(OpCodes.Callvirt,assembly.MainModule.ImportReference(TypeHelpers.ResolveMethod("System.Net.Http","System.Net.Http.HttpClient","GetAsync",System.Reflection.BindingFlags.Default|System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.Public,"","System.String")));
    var Ldloc35 = il_CodeInsight_WorkThreadFunction_.Create(OpCodes.Ldloc,lv_urlParameters10);
    il_CodeInsight_WorkThreadFunction_.Append(Ldloc35);
    il_CodeInsight_WorkThreadFunction_.Append(Callvirt34);
    var Stloc36 = il_CodeInsight_WorkThreadFunction_.Create(OpCodes.Stloc,lv_res32);
    il_CodeInsight_WorkThreadFunction_.Append(Stloc36);

此代码生成这些IL

|       > IL_0000: ldloc V_2
|       > IL_0000: ldloc V_1
|       > IL_0000: callvirt System.Threading.Tasks.Task`1<System.Net.Http.HttpResponseMessage> System.Net.Http.HttpClient::GetAsync(System.String)
|       > IL_0000: stloc V_3

当我运行代码时,出现以下错误:

Hello from OtherUnhandled exception. System.InvalidProgramException: Common Language Runtime detected 
an invalid program.
   at QualityInsight.CodeInsight.WorkThreadFunction()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,Object state)
   at System.Threading.ThreadHelper.ThreadStart()

任何人都可以在这里帮忙...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...