我遇到了同样的错误。上面提到的建议对我不起作用。运行后我收到以下错误
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'System.Windows.Application' threw an exception.
Source=PresentationFramework
StackTrace:
at System.Windows.Application..ctor()
at ShortBarDetectionSystem.App..ctor()
at ShortBarDetectionSystem.App.Main()
Inner Exception 1:
TypeInitializationException: The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception.
Inner Exception 2:
TypeInitializationException: The type initializer for 'MS.Internal.TraceDependencyProperty' threw an exception.
Inner Exception 3:
ConfigurationErrorsException: Configuration system failed to initialize
Inner Exception 4:
ConfigurationErrorsException: Section or group name 'oracle.manageddataaccess.client' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\ShortBarDetectionSystem\code\framework\TypeInitializationException\ver0_1\ShortBarDetectionSystem\ShortBarDetectionSystem\bin\x64\Debug\GrateBarDefectDetectionSystem.exe.Config line 4)
我的 exe.config 文件第 4 行出现错误。.exe.config 文件是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
但是经过反复试验,我发现删除 configSections
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
为我工作。