我在一个asp.net Web表单应用程序中使用Ninject的2.2.0.0版本,在几百个请求之后,它有时会在Binding类的GetProvider方法中抛出NullReferenceException.
堆栈跟踪示例:http://pastebin.com/BbhsPQMT
仅当我对应用程序进行压力测试并且异常的来源通常不同(解析不同的接口)时才会发生异常.
为了试图理解为什么会出现这个问题,我查看了Ninject源代码并插入了一些代码行以用于调试目的.我后来确认null的对象是Binding类中的ProviderCallback属性.
我还在ProviderCallback属性的set运算符中放入了一些代码,以便了解它是否被设置为null.在运行一些测试并查看一些内存转储后,似乎ProviderCallback属性未设置为空值,因此我认为GC正在收集该实例.
我仍然不明白为什么会发生这种情况......
任何帮助是极大的赞赏.
编辑:我们升级到最新版本的Ninject只是为了检查异常是否仍然发生但我们在对应用程序进行压力测试后得到了相同的异常:http://pastebin.com/YaiaZndz
有没有人知道为什么在下列情况下调用GetRuntimeMethod返回null?
_toListMethod = typeof(Enumerable).GetRuntimeMethod("ToList", new Type[] { typeof(IEnumerable<>) });
Run Code Online (Sandbox Code Playgroud)
它应该像它一样工作:
_castMethod = typeof(Enumerable).GetRuntimeMethod("Cast", new Type[] { typeof(IEnumerable) });
Run Code Online (Sandbox Code Playgroud)
我尝试通过运行以下代码来调试它:
var bah = typeof (Enumerable).GetRuntimeMethods().Where(m => m.Name.Contains("ToList"));
var derp = bah.First().GetParameters();
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,第一行返回一个集合,其中包含我想要获取的MethodInfo,第二行确认预期的参数类型是IEnumerable <>.
两个方法签名,Cast和ToList是相似的,我看不出为什么为ToList获取MethodInfo会失败的任何原因.
此代码在可移植类库上运行,TargetFrameworkProfile设置为Profile78.
谢谢!
更新:在我有一个很好的解决方案之前,有一个丑陋的解决方法对我有用:
_toListMethod = typeof(Enumerable).GetRuntimeMethods().First(m => m.Name.Contains("ToList"));
Run Code Online (Sandbox Code Playgroud) 我有一个NUnit单元测试,它是用普通的F#库编写的,但它是针对可移植类库中的F#代码.
当我运行此测试(在Visual Studio 2013中)时,我得到以下异常:
Result Message: System.MissingMethodException : Method not found:
'Microsoft.FSharp.Control.FSharpAsync`1<System.IO.TextReader> FSharp.Data.Runtime.IO.asyncReadTextAtRuntime(System.Boolean, System.String, System.String, System.String, System.String)'.
Run Code Online (Sandbox Code Playgroud)
这就是我在Portable Class Library中的app.config中所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这就是我在普通F#库的app.config中所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.3.13283" newVersion="2.6.3.13283" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)