wpf “System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发了 Windows XP 的异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27211626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
the type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception for Windows XP
提问by Kirsten Greed
My WPF application works fine on Windows 7, but throws the above error when running on Windows XP. I am using ENtity Framework 6.1.1
我的 WPF 应用程序在 Windows 7 上运行良好,但在 Windows XP 上运行时会引发上述错误。我正在使用实体框架 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. Could it be interpreted differently on XP?
app.config 包含正确的连接字符串。它可以在 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="Database=mydatabase;Server=Server15\SQLExpress;Integrated Security=False;User=mylogin;Password=mypassword;MultipleActiveResultSets=True;App=EntityFramework"" 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 删除和重新添加实体框架
[Update]
[更新]
Thank you ErikEJ. Copying the files locally works. I wonder if there is a way to get it working on the network?
谢谢 ErikEJ。在本地复制文件有效。我想知道是否有办法让它在网络上工作?
Reminds me of my problem in this question about regasm
让我想起我在这个关于 regasm 的问题中的问题
采纳答案by ErikEJ
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.
Q:驱动是本地的吗?如果没有,请尝试从本地驱动器运行该应用程序 - 错误消息表明存在安全问题,阻止您从网络文件夹运行。

