[英]Exception Unhandled by User Code
I have a member of a library being declared on the main page of my app: 我的应用程序主页上声明了一个库的成员:
private OpticalReaderLib.OpticalReaderTask _task = new OpticalReaderLib.OpticalReaderTask();
It works fine until I want to navigate back to this page at a different time. 在我想在其他时间导航回到此页面之前,它工作正常。 It brings up the error "An exception of type 'System.Exception' occurred in OpticalReaderLib.DLL but was not handled in user code". 出现错误“ OpticalReaderLib.DLL中发生了'System.Exception'类型的异常,但未在用户代码中处理”。
Does anyone know why this is happening? 有人知道为什么会这样吗?
Thanks. 谢谢。
System.Exception is the base class for all Exceptions, so this is a very generic error message. System.Exception是所有Exception的基类,因此这是一条非常通用的错误消息。
You could try logging more detail (eg exception.Message or exception.InnerException) about the exception that is thrown as part of your investigation. 您可以尝试记录有关在调查过程中引发的异常的更多详细信息(例如exception.Message或exception.InnerException)。 (via a try-catch statement). (通过try-catch语句)。
It looks like you're initialising a field, where is this code being executed? 好像您正在初始化一个字段,此代码在哪里执行?
Update due to comment As a temporary solution to discover the exception error. 由于注释而更新作为发现异常错误的临时解决方案。
private OpticalReaderLib.OpticalReaderTask _tempTask;
private OpticalReaderLib.OpticalReaderTask _task
{
get
{
//code to debug the error that is occuring
try
{
if (_tempTask == null)
_tempTask = new OpticalReaderLib.OpticalReaderTask();
else
return _tempTask;
}
catch (Exception exception)
{
//Log the exception detail here
}
}
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (_task != null)
{
_task.Completed -= OpticalReaderTask_Completed;
_task.Dispose();
_task = null;
}
base.OnBackKeyPress(e);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.