相关疑难解决方法(0)

C#中的WPF类型初始化异常

我有其他人的基于WPF的.NET 3.5应用程序,我正在尝试更新到.NET 4.5.该代码在.NET 3.5细跑了,而我在运行Visual Studio 2013快车在Windows 7的更新似乎顺利,代码编译罚款,但是当我尝试运行应用程序,我得到下面的异常.

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

Additional information: The type initializer for 'System.Windows.Application' threw an exception.
Run Code Online (Sandbox Code Playgroud)

以下是stacktrace中的最后几个步骤.

PresentationFramework.dll!System.Windows.Windows.Application()
MiniMon.exe!MiniMon.App.App()
MiniMon.exe!MiniMon.App.Main()
Run Code Online (Sandbox Code Playgroud)

这是app.xaml文件.

<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>
Run Code Online (Sandbox Code Playgroud)

我可以下载一个示例WPF应用程序(WPFCalculator),它运行正常,所以我尝试将我正在更新的那个剥离到示例应用程序中的内容.我还尝试在app.xaml.cs中的代码的入口点添加断点,但是在执行该代码之前抛出了异常.作为最后的手段,我尝试在Windows 8上运行该应用程序,但得到了同样的错误.

如何解决这个问题?

.net c# wpf xaml

10
推荐指数
4
解决办法
2万
查看次数

在 .Net 4.7.2 中导入 AngleSharp 时绑定重定向以某种方式尝试将 NetStandard 2 作为 dll 引入

我有一个旧版应用程序在旧的 Windows 2008 R2 服务器上运行。该应用程序经历了许多 .Net 版本,目前在 4.7.2 上。多年来,它一直稳定如磐石,虽然有迁移计划以摆脱旧的物理服务器,但它必须存活一段时间。

一项新功能表明需要一些 HTML 抓取。我为 AngleSharp v0.12.0 添加了 NuGet 包,经过单元测试,在我的 Win10 开发机器上一切正常。使用 AngleSharp 的新类很简单。

所以我部署到 prod 服务器,包括对 app.config 的更改;

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
Run Code Online (Sandbox Code Playgroud)

这些是我可以从旧版本中识别出的唯一更改。

当我在生产中运行该应用程序时,它崩溃了。

System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the …
Run Code Online (Sandbox Code Playgroud)

c# assembly-binding-redirect anglesharp .net-4.7.2

5
推荐指数
2
解决办法
1387
查看次数

更改项目名称和名称空间后未定义c#properties/settings

我正在更新几年前构建的旧应用程序,全局命名空间和project.cs文件以及主窗体都被命名为 email2case_winForm

我想改变它(除了以更多的OOP方式重建应用程序以使其更灵活,并且能够重用代码),因此将名称更改为 email2case

但是现在我在编译时遇到了问题,因为在阅读项目的设置和属性时,找不到这些成员.

这是我试图用来读取属性的代码示例.设置:

XElement x = XElement.Load(email2case.Properties.Settings.Default.e2cConfigFile);
Run Code Online (Sandbox Code Playgroud)

并且该编译器的错误是:

'email2case.email2case'不包含'属性'的定义

以下是一个类如何从全局设置中读取:

this.Url = global::email2case.Settings.Default.email2case_sforce_SforceService;
Run Code Online (Sandbox Code Playgroud)

并且该编译器的错误是:

名称空间"email2case"中不存在类型或命名空间名称"设置"(您是否缺少程序集引用?)

我有一种预感,问题是由定义引起的app.Config,这里是:

<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="email2case.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
            <section name="email2case.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="email2case.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
      <email2case.Properties.Settings>
        <setting name="email2case_sforce_SforceService" serializeAs="String">
          <value>https://login.salesforce.com/servi...</value>
        </setting>
        <setting name="e2cConfigFile" serializeAs="String">
          <value>C:\email2case\data\e2cConfig.xml</value>
        </setting>
      </email2case.Properties.Settings> …
Run Code Online (Sandbox Code Playgroud)

.net c# projects-and-solutions winforms

3
推荐指数
1
解决办法
9049
查看次数