在C#WPF类型初始化异常 [英] WPF Type initialization Exception in C#

查看:808
本文介绍了在C#WPF类型初始化异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有别人的基于WPF的是我试图更新到.NET 4.5 .NET 3.5的应用程序。该代码细跑下.NET 3.5,而我在运行Visual Studio 2013速成在Windows 7更新似乎顺利,代码编译很好,但是当我尝试运行应用程序我得到下面的异常。

I have someone else's WPF-based .NET 3.5 app that I'm attempting to update to .NET 4.5. The code ran fine under .NET 3.5, and I'm running Visual Studio 2013 Express on Windows 7. The update seemed to go well and the code compiles fine, but when I try to run the app I get the following exception.

An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll

Additional information: The type initializer for 'System.Windows.Application' threw an exception.

下面是堆栈跟踪的最后几个步骤。

Here are the last few steps in the stacktrace.

PresentationFramework.dll!System.Windows.Windows.Application()
MiniMon.exe!MiniMon.App.App()
MiniMon.exe!MiniMon.App.Main()

下面是App.xaml文件。

Here's the app.xaml file.

<Application x:Class="MiniMon.App"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 StartupUri="Window1.xaml">
<Application.Resources>
</Application.Resources>
</Application>



我可以下载示例WPF应用程序(WPFCalculator),并运行良好,所以我尝试剥离之一我更新到正是在示例应用程序。我也试过在app.xaml.cs代码的入口点添加一个断点,但被执行的代码甚至在抛出异常。作为最后的手段我试图在Windows 8上运行的应用程序,但得到了同样的错误。

I can download a sample WPF app (WPFCalculator) and it runs fine, so I tried stripping the one I'm updating down to just what was in the sample app. I also tried adding a breakpoint at the entry point of the code in app.xaml.cs, but the exception is thrown even before that code is executed. As a last resort I tried running the app on Windows 8, but got the same error.

有什么想法?

感谢。

推荐答案

一(不是很有教育意义)的解决方法是开始一个新的4.5的项目,并复制粘贴相关件从旧的代码。

One (not very educational) workaround would be to start a new 4.5 project, and copy-paste the relevant pieces of code from the old one.

这篇关于在C#WPF类型初始化异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆