Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

c# - Strange System.__Canon exception

I have a windows service that uses a singleton class ThreadQueue<T>. When the service starts it makes a call to ThreadQueue<string>.Start() this class then accepts and queues tasks limiting the concurrency to a configurable number of threads.

ThreadQueue<string>.Start() is called once and only once when the service starts up.

On occasion, after a few hours of the service running i receive the following 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()

What is System.__Canon and what is making this call passing in this as a type argument?

Can anyone shed any light?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should not read anything in the method argument type name. System.__Canon is an implementation detail related to the way generics are implemented in the CLR. I don't know the exact usage for it but strongly suspect it is used by Ngen.exe, the optimization tool in .NET that pre-jits assemblies. Generics are a problem in pre-jitting since the concrete type is instantiated at runtime. You'll get multiple copies of a method that takes an argument type of a type parameter. Just one method that handles any reference type, additional methods for each value type, if any. System.__Canon can be the substitute type that's the place holder for any reference type, allowing Ngen.exe to prejit that method even though it cannot guess what actual type will be used at runtime. Something like that.

The shoe fits, Apollo.Business.Framework.Threading.ThreadQueue sounds like the kind of class that's present in a framework style library that would be pre-jitted when it is installed since it was meant to be used by multiple programs.

So ignore the type name, focus on the actual exception. NullReferenceException is a very common exception of course. Nothing is otherwise visible from the stack trace that would give a hint what causes it. I'd guess at an initialization problem with that "Apollo" framework, some object that should have a value but is still null. Having a peek at the source code for the ThreadQueue constructor should give a hint. A call to the vendor for help if you don't have it. A bug in a 8 year old version of the jitter doesn't explain it well, those bugs have been fixed a long time ago.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...