简体   繁体   English

'System.Data.Entity.Internal.AppConfig'的类型初始值设定项引发了Windows XP的异常

[英]the type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception for Windows XP

My WPF application works fine on Windows 7, but throws the above error when running on Windows XP. 我的WPF应用程序在Windows 7上运行正常,但在Windows XP上运行时会抛出上述错误。 I am using ENtity Framework 6.1.1 我正在使用ENtity Framework 6.1.1

App.xaml is App.xaml是

<Application.Resources>
    <main:MainConverter x:Key="MainVerter"/>
    <Style x:Key="DetailHead1Style" TargetType="TextBlock">
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Foreground" Value="DarkSlateGray"/>
        <Setter Property="Opacity" Value="0.8"/>
        <Setter Property="FontStyle" Value="Italic"/>
        <Setter Property="Margin" Value="6,2,6,2"/>
    </Style>
    <Style  x:Key="DetailsOuterGridStyle" TargetType="Grid">
        <Setter Property="Background" Value="White"/>
    </Style>
</Application.Resources>

The inner exception is 内在的例外是

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for entityFramework: Request failed. 
(Q:\devnet10\SBD.CartBrowser\SBD.CartBrowser\bin\Debug\SBD.FlightControl.exe.Config line 23) ---> System.Security.SecurityException: Request failed.
       at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
       at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
       at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
       at System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(ConstructorInfo ctor)
       at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
       at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
       at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
       at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)

The app.config contains the correct connection string. app.config包含正确的连接字符串。 Could it be interpreted differently on XP? 可以在XP上进行不同的解释吗?

[Update] The code fails when initialising the connection. [更新]初始化连接时代码失败。

 var connect = new CartConnect(constr);

[Update] [更新]

app.config is app.config是

 <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>

  <connectionStrings>
    <add name="CartConnect_HAPPY4" connectionString="metadata=res://*/Edm.CartModel.csdl|res://*/Edm.CartModel.ssdl|res://*/Edm.CartModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Database=mydatabase;Server=Server15\SQLExpress;Integrated Security=False;User=mylogin;Password=mypassword;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>

   <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
   </startup>

</configuration>

I set up my connection string using 我使用设置连接字符串

private CartConnect MakeConnect()
{
    string key = string.Format("CartConnect_{0}", Environment.MachineName.ToUpperInvariant());
    string constr = ConfigurationManager.ConnectionStrings[key].ConnectionString;
    var connect = new CartConnect(constr); // fails here

    connect.Configuration.LazyLoadingEnabled = false;

    connect.Configuration.ProxyCreationEnabled = false;

    return connect;
}

I looked at other questions on "An error occurred creating the configuration section handler for entityFramework" 我查看了有关“为entityFramework创建配置节处理程序时发生错误”的其他问题

I tried removing and re-adding Entity Framework using NuGet 我尝试使用NuGet删除并重新添加Entity Framework

[Update] [更新]

Thank you ErikEJ. 谢谢ErikEJ。 Copying the files locally works. 在本地复制文件有效。 I wonder if there is a way to get it working on the network? 我想知道是否有办法让它在网络上运行?

Reminds me of my problem in this question about regasm 让我想起这个关于regasm的问题

Is the Q: drive local? 问:驱动本地吗? If not, try to run the app from a local drive - the error message indicates that there is a security issue preventing you to run from a network folder. 如果没有,请尝试从本地驱动器运行该应用程序 - 错误消息表明存在阻止您从网络文件夹运行的安全问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理typeinitializationexception。&#39;System.Data.Entity.Internal.AppConfig&#39;的类型初始值设定项引发了异常 - typeinitializationexception was unhandled .The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception &#39;System.Data.Entity.Internal.AppConfig&#39;的类型初始化程序在子网站上引发了一个例外 - The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception on a Sub Website SQL Server Express “'system.data.entity.internal.appconfig' 的类型初始化程序引发异常”错误 - SQL Server Express “the type initializer for 'system.data.entity.internal.appconfig' threw an exception” error 在 .NET4.5 上安装 EntityFramework5.0.0 后错误:“System.Data.Entity.Internal.AppConfig”的类型初始化程序在运行时引发异常 - After installing EntityFramework5.0.0 on .NET4.5 Error: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception at Runtime System.Data.Entity.MigrateDatabaseToLatestVersion 的类型初始值设定项引发异常 - The type initializer for System.Data.Entity.MigrateDatabaseToLatestVersion threw an exception 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' 的类型初始值设定项抛出异常 - The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception &#39;System.Data.Entity.Migrations.DbMigrationsConfiguration`1&#39;的类型初始值设定项引发了Oracle数据库异常 - The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception with Oracle Database “ System.Windows.Navigation.BaseUriHelper”的类型初始值设定项引发了异常 - The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception &#39;System.Data.SqlClient.SqlConnection&#39;的类型初始值设定项引发异常.Windows Server 2016 - The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.Windows server 2016 System.Data.SqlClient的类型初始值设定项引发了异常 - type initializer for System.Data.SqlClient threw an exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM