字段未找到异常 [英] Field not found exception
问题描述
你好,
我想我发现了一个错误,其中合同代码正在优化我的一个变量。启用代码合同后,我收到此错误:
$
System.MissingFieldException未处理
消息=未找到字段:'M6.Server.Threading.Worker._shouldStop'。
来源= SF.Server.Engine
StackTrace:
在SF.Server.Engine.Utilities.SaveChangesWorker.DoWork(Object anObject)
at System.Threading.ExecutionContext.runTryCode(Object userData)
在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)
在System.Threading.ThreadHelper.ThreadStart(Object obj)
InnerException:
$
关闭运行时检查可以解决问题。我在Windows 7 x64下运行版本1.2.30312.0,.Net 4,VS2010。
添加[ContractVerification(false)]不会改变行为。
这里是代码:
Hello,
I think I have discovered a bug in which the contract code is optimizing away one of my variables. With code contracts enabled, I get this error:
System.MissingFieldException was unhandled
Message=Field not found: 'M6.Server.Threading.Worker._shouldStop'.
Source=SF.Server.Engine
StackTrace:
at SF.Server.Engine.Utilities.SaveChangesWorker.DoWork(Object anObject)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
InnerException:
Turning off runtime checking fixes the problem. I am running version 1.2.30312.0, .Net 4, VS2010 under Windows 7 x64.
Adding [ContractVerification(false)] does not change the behavior.
Here’s the code:
public interface IWorker
{
void DoWork(object anObject);
}
public enum WorkerState
{
Starting = 0,
Started,
Stopping,
Stopped,
Faulted
}
public class Worker : IWorker
{
public WorkerState State { get; set; }
public virtual void DoWork(object anObject)
{
while (!_shouldStop)
{
// Do some work
}
// thread is stopping
// Do some final work
}
public void RequestStop()
{
State = WorkerState.Stopping;
_shouldStop = true;
}
protected volatile bool _shouldStop;
}
public class SaveChangesWorker : Worker
{
public override void DoWork(object anObject)
{
while (!_shouldStop)
{
} // while
}
}
我不知道如何解决这个问题,除了停止使用我不想做的代码合同。
谢谢,b
Rick
I have no clue how to fix this other than stop using code contracts which I’d rather not do.
Thank you,
Rick
推荐答案
嗨瑞克,
你做过干净吗?重建?
我经常得到Exception'System.MissingFieldException',当我只更改IDE中的一些代码并重新启动时,没有干净&重建。
I often get the Exception 'System.MissingFieldException', when I only change some code in the IDE and restart, without clean & rebuild.
此外,您的示例似乎不完整,主要在哪里?
Also your example doesn't seems to be complete, where is the main?
我确实尝试过,添加:
static void Main(string[] args)
{
(new SaveChangesWorker()).DoWork(null);
}
但是我没有得到例外。
这是什么项目类型?
but I don't get the Exception.
What Project type is this?
还需要测试其他什么吗?
Anything else needed to test?
这篇关于字段未找到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!