奇怪的系统.__佳能exception

我有一个使用单例类ThreadQueue的Windows服务。 当服务启动时,它调用ThreadQueue.Start()然后该类接受并将限制并发的任务排队到可配置数量的线程。

ThreadQueue.Start()只在服务启动时调用一次。

有时,在运行几个小时后,我收到以下exception:

 Application: myservice.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException Stack: at Apollo.Business.Framework.Threading.ThreadQueue.ThreadQueue`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start() at System.Threading.ThreadHelper.ThreadStart_Context(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ThreadHelper.ThreadStart() 

什么是System.__Canon和什么使这个调用作为类型参数传递给它?

谁能摆脱任何光明?

您不应该在方法参数类型名称中读取任何内容。 System .__ Canon是与CLR中实现generics的方式相关的实现细节。 我不知道它的确切用法,但强烈怀疑它是由Ngen.exe使用的,它是.NET中预先组装程序集的优化工具。 generics是预先编写的问题,因为具体类型是在运行时实例化的。 您将获得一个采用类型参数的参数类型的方法的多个副本。 只有一种处理任何引用类型的方法,每种值类型的附加方法(如果有的话)。 System .__ Canon可以是替代类型,它是任何引用类型的占位符,允许Ngen.exe预先调用该方法,即使它无法猜测在运行时将使用的实际类型。 这样的事情。

鞋子适合,Apollo.Business.Framework.Threading.ThreadQueue听起来像是一种类型,它存在于框架样式库中,在安装时会被预先安装,因为它是由多个程序使用的。

因此忽略类型名称,关注实际exception。 NullReferenceException当然是一个非常常见的例外。 从堆栈跟踪中看不到任何可以提示它的原因。 我猜这个“Apollo”框架的初始化问题,一些对象应该有一个值,但仍然是null。 看一下ThreadQueue构造函数的源代码应该给出一个提示。 如果您没有,请致电供应商寻求帮助。 一个8岁版本的抖动中的错误并不能很好地解释它,这些错误很久以前就得到了解决。

现在运行时和框架已经开源,回答这类问题要容易得多。 __Canon的定义可在此处获得 。 引用:

 // Internal methodtable used to instantiate the "canonical" methodtable for generic instantiations. // The name "__Canon" will never been seen by users but it will appear a lot in debugger stack traces // involving generics so it is kept deliberately short as to avoid being a nuisance. [Serializable] [ClassInterface(ClassInterfaceType.AutoDual)] [System.Runtime.InteropServices.ComVisible(true)] internal class __Canon { } 

正如评论所解释的那样,它是generics的实现细节,是“canonical”的缩写。