錯誤在微軟社區,沒人解決,看來洋鬼子還是不咋地,沒CNBLOGS人熱心^_^
首先看異常提示:
JIT Compiler encountered an internal limitation.
程式碼:
在運行委託的時候,就異常了。
代碼
private decimal ProductKPIdata(Type type,string methodName,Guid userId,int year)
{
var cache = HttpRuntime.Cache;
if (cache[methodName] != null)
return ((Func<Guid, int, decimal>)cache[methodName])(userId,year);
var dynamicMethod = new DynamicMethod("Gan",typeof(decimal), new Type[] { typeof(Guid), typeof(int) },typeof(AnalyzeResultBLL).Module);
var ilGen = dynamicMethod.GetILGenerator();//IL產生器
//把參數推到堆棧上
ilGen.Emit(OpCodes.Ldarg_0);
ilGen.Emit(OpCodes.Ldarg_1);
ilGen.Emit(OpCodes.Ldarg_2);
ilGen.Emit(OpCodes.Call, type.GetMethod(methodName, new Type[] { typeof(Guid), typeof(int) }));
ilGen.Emit(OpCodes.Ret);//結束並傳回值
//產生委託
Func<Guid, int, decimal> gan =
(Func<Guid, int, decimal>)dynamicMethod.CreateDelegate(typeof(Func<Guid, int, decimal>));
//委託放入緩衝
cache.Insert(methodName,gan);
//調用委託返回結果
return gan(userId,year);
}
至於為什麼搞這麼個垃圾方法,也是特殊原因,搞累了,都說不來了,只是貼出錯誤的地方,本著問題的核心,所以
如果有說參數、方法啊其他的問題就免了,核心問題是異常。許可權?到底這麼解決?