c# - 在 VS2012 中获取 TypeInitializationException,但不是 2010

标签 c# wpf visual-studio-2010 visual-studio

当我尝试在 Visual Studio 2012 中调试我的应用程序时,我收到了一个TypeInitializationException,但我能够在 Visual Studio 2010 中无错误地运行该应用程序。

我最近移动了一堆东西(包括我的项目和一些引用资料),以便将其纳入版本控制系统。我必须重新链接几个项目,以便在不同系统上 checkout 时所有内容都能正确链接。

我们的开发环境是混合的(VS2010 & VS2012)。用完 VS2010 没有产生任何错误。但是当我在 VS2012 中运行调试时,我收到了 TypeInitializationException 异常。

原始 目录中的项目(在出于版本控制目的而移动之前它所在的位置)在 VS2010 和 VS2012 中仍然运行良好。

有一个标志或参数或某处有点困惑的东西,但我不确定在哪里。有没有人知道我可以做些什么来让它在 VS2012 中也能正常工作?

(如果有的话,请告诉我要在此处包含的代码或配置信息)

内部异常:

The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception.

(第二个)InnerException:

The type initializer for 'MS.Internal.TraceDependencyProperty' threw an exception.

最佳答案

对原始问题的评论引发了进一步的搜索,最终产生了解决方案。

正在搜索“'System.Windows.Navigation.BaseUriHelper' 的类型初始值设定项引发异常。”我发现了以下 StackOverflow 问题:WPF Application fails on startup with TypeInitializationException

与那个问题类似,我添加了一个 <startup> </startup>阻止我的“app.config”文件。放置此标记 block 的位置有所不同:

导致 VS2012 错误:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
    </startup>
    <configSections>
       ...
    </configSections>
    <applicationSettings>
       ...
    </applicationSettings>
</configuration>

一切正常:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
       ...
    </configSections>
    <applicationSettings>
       ...
    </applicationSettings>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
    </startup>
</configuration>

将标签 block 移到底部就成功了!

关于c# - 在 VS2012 中获取 TypeInitializationException,但不是 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13632489/

相关文章:

c# - 使用 RtlCopyMemory 在驱动程序中复制数据

c# - 在 WPF 中向 DataGridTextColumn 添加填充

c# - 使用 C# 将记录插入 SQL Server 2012

wpf - 动画 TranslateTransform.Y 到控件的高度(目的是将元素滑出视线)

visual-studio-2010 - VS2010数据库项目有没有办法抑制SQL03006错误?

c++ - Visual C++,没有试图添加 .dll 的引用

c# - 在 C# 中传递具有 N 个参数作为参数的方法

c# - 使用 Azure 进行桌面应用程序日志

javascript - C# 中的 CustomValidator 未拾取颜色

c# - WPF 组合框对更改不具有约束力