微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何使用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 举报,一经查实,本站将立刻删除。