-2

我正在使用 C# 编写智能卡系统。在我未发布的程序中,它没有显示任何错误并且运行顺利。

但是当我将它转换为安装程序并运行它的 exe 文件时,它会显示错误object reference not set to an instance of an object。知道为什么这会发生在 exe 文件中吗?

4

1 回答 1

2

To help you locate the problem you can idetify where in the code this is happening by catching all unhandled exceptions and logging them in a manor that is fit for your application.

Now each application type has different methods for catching unhandled exceptions. Here are some basic pointers for different types.

WinForms: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx

WPF : http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx

WebForms \ MVC : http://msdn.microsoft.com/en-us/library/24395wz3(v=vs.100).aspx

Now how you log is your own responsibility you can use some off the shelf \ OS features if you wish.

log4net: http://logging.apache.org/log4net/

EventLogs: http://support.microsoft.com/kb/307024

Back to original problem. The reason you are getting the error is you are accessing \ manipulating an object that is not set. Now which object and why is quite difficult to trace and impossible for us to resolve without some indication as to where this error is ocurring. At a minimum we would need to know where in the code this is happening.

Ideally a full stack trace will resolve this quite quickly.

Cheers.

于 2013-11-14T03:16:59.393 回答