首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >奇怪的System.__Canon异常

奇怪的System.__Canon异常
EN

Stack Overflow用户
提问于 2013-05-31 17:44:23
回答 2查看 10.7K关注 0票数 12

我有一个使用单例类ThreadQueue<T>的windows服务。当服务启动时,它调用ThreadQueue<string>.Start()这个类,然后接受任务并对其进行排队,将并发限制为可配置的线程数量。

ThreadQueue<string>.Start()在服务启动时调用一次,且仅调用一次。

有时,在服务运行几个小时后,我会收到以下异常:

代码语言:javascript
复制
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?是什么让这个调用以类型参数的形式传入?

有没有人能提供一点线索?

EN

回答 2

Stack Overflow用户

发布于 2013-05-31 19:26:38

您不应该读取方法参数类型名称中的任何内容( not read )。System.__Canon是与在CLR中实现泛型的方式相关的实现细节。我不知道它的确切用法,但我强烈怀疑它是由Ngen.exe使用的,它是.NET中预压缩程序集的优化工具。泛型是预压缩中的一个问题,因为具体类型是在运行时实例化的。您将获得一个方法的多个副本,该方法采用类型参数的实参类型。只有一个方法处理任何引用类型,每个值类型的附加方法,如果有的话。System.__Canon可以是任何引用类型的占位符的替代类型,允许Ngen.exe预置该方法,即使它不能猜测在运行时将使用什么实际类型。差不多吧。

这只鞋很合适,Apollo.Business.Framework.Threading.ThreadQueue听起来像是框架样式库中存在的那种类,在安装它时会预压缩,因为它意味着要被多个程序使用。

所以忽略类型名,专注于实际的异常。当然,NullReferenceException是一个非常常见的例外。从堆栈跟踪中看不到任何东西,这将给出导致它的原因的提示。我猜是"Apollo“框架初始化问题,一些对象应该有一个值,但仍然是空的。浏览一下ThreadQueue构造函数的源代码应该会给出一些提示。如果你没有,可以打电话给供应商寻求帮助。一个8年前的抖动版本中的错误并不能很好地解释它,这些错误很久以前就被修复了。

票数 23
EN

Stack Overflow用户

发布于 2016-01-12 04:40:55

既然运行时和框架已经开源,回答这类问题就容易多了。引用:

代码语言:javascript
复制
// 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
{
}

正如评论所解释的,它是泛型的实现细节,是"canonical“的缩写。

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16854393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档