由于 Visual Studio 生成的代码,C# 应用程序无提示地崩溃
C# application crashes silently due to Visual Studio generated code
我创建了一个我非常想部署的简单应用程序,但是每当我在另一台不是我的机器上安装该应用程序时,该应用程序就会无声地崩溃。因为没有错误被抛出或应用程序失败的任何通知。对该问题的进一步研究使我查看了 windows 保留的错误日志。我按照异常 <SystemArgument>
一直到应用程序中的代码,但我不知道该怎么做,因为我所做的任何更改都将在下次 build.Here 时被覆盖,这是我从错误中得到的日志:
事件数据:
Application: bbcg.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
异常:
Info: System.ArgumentException Stack: at MS.Internal.Resources.ResourceManagerWrapper.GetStream(System.String) at MS.Internal.AppModel.ResourcePart.EnsureResourceLocationSet() at MS.Internal.AppModel.ResourcePart.GetContentTypeCore() at System.IO.Packaging.PackagePart.get_ContentType() at System.Windows.Application.LoadComponent(System.Object, System.Uri) at Report_Form_Generator.App.InitializeComponent() at Report_Form_Generator.App.Main()
我没有想法,任何帮助都非常重要。我该如何避免这个错误?
您可以在您的应用程序中实施 UnhandledException
和 ThreadException
异常处理程序以捕获未处理的异常并获取有关错误的更多信息:
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs ex)
{
// log the exception or do other work
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs ex)
{
// log the exception or do other work
}
将应用程序程序集信息中的中性语言从项目属性更改为 None。
我创建了一个我非常想部署的简单应用程序,但是每当我在另一台不是我的机器上安装该应用程序时,该应用程序就会无声地崩溃。因为没有错误被抛出或应用程序失败的任何通知。对该问题的进一步研究使我查看了 windows 保留的错误日志。我按照异常 <SystemArgument>
一直到应用程序中的代码,但我不知道该怎么做,因为我所做的任何更改都将在下次 build.Here 时被覆盖,这是我从错误中得到的日志:
事件数据:
Application: bbcg.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
异常:
Info: System.ArgumentException Stack: at MS.Internal.Resources.ResourceManagerWrapper.GetStream(System.String) at MS.Internal.AppModel.ResourcePart.EnsureResourceLocationSet() at MS.Internal.AppModel.ResourcePart.GetContentTypeCore() at System.IO.Packaging.PackagePart.get_ContentType() at System.Windows.Application.LoadComponent(System.Object, System.Uri) at Report_Form_Generator.App.InitializeComponent() at Report_Form_Generator.App.Main()
我没有想法,任何帮助都非常重要。我该如何避免这个错误?
您可以在您的应用程序中实施 UnhandledException
和 ThreadException
异常处理程序以捕获未处理的异常并获取有关错误的更多信息:
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs ex)
{
// log the exception or do other work
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs ex)
{
// log the exception or do other work
}
将应用程序程序集信息中的中性语言从项目属性更改为 None。