gpt4 book ai didi

c# - WCF 数据服务的 VerificationException

转载 作者:行者123 更新时间:2023-11-30 17:44:18 26 4
gpt4 key购买 nike

我使用 .Net 4.5.2 和 Entity Framework 6.1.3 创建了一个基本的 WCF 数据服务和 Entity Framework。数据库中只有一张表。

配置如下:

public class MyDataService : DataService<DataItemsDataContext>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
config.SetEntitySetAccessRule("DataItem", EntitySetRights.All);
}
}

当我启动项目时,我可以看到:

网址:http://localhost:49570/MyDataService.svc/

内容:

<service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="http://localhost:49570/MyDataService.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="DataItem">
<atom:title>DataItem</atom:title>
</collection>
</workspace>
</service>

当我选择表格时,出现以下异常:

网址:http://localhost:49570/MyDataService.svc/DataItem

内容:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code/>
<m:message xml:lang="en-US">An error occurred while processing this request.</m:message>
<m:innererror>
<m:message>Operation could destabilize the runtime.</m:message>
<m:type>System.Security.VerificationException</m:type>
<m:stacktrace>
at: queryable_reader(Object )
at: System.Data.Services.Providers.ReflectionServiceProvider.GetQueryRootForResourceSet(ResourceSet container)
at: System.Data.Services.Providers.ReflectionDataServiceProvider.GetQueryRootForResourceSet(ResourceSet resourceSet)
at: System.Data.Services.Providers.DataServiceProviderWrapper.GetQueryRootForResourceSet(ResourceSetWrapper resourceSet)
at: System.Data.Services.RequestUriProcessor.ComposeExpressionForEntitySet(SegmentInfo segment, IDataService service, Boolean isLastSegment, Boolean checkRights)
at: System.Data.Services.RequestUriProcessor.ComposeExpressionForSegments(IList`1 segments, IDataService service, Boolean isCrossReferencingUri)
at: System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service, Boolean internalQuery)
at: System.Data.Services.DataService`1.ProcessIncomingRequestUri()
at: System.Data.Services.DataService`1.HandleRequest()
</m:stacktrace>
</m:innererror>
</m:error>

可能是some .Net bug .

什么会导致这种情况?我应该改变什么?

最佳答案

看起来它确实是一个错误(或者至少是一个限制性功能)。

首先,我使用Entity Framework 6.1.3作为数据库ORM,出现错误。

当我切换回 Entity Framework 5.0 时,服务正常运行。

根据这个KB article :

Assume that you upgrade an earlier version of the .NET Framework to the .NET Framework 4.5 on a computer. When you use some third-party controls, you may receive a System.Security.VerificationException exception. This issue occurs if the following conditions are true:

  • The third-party controls use the generic types.
  • The CLR verifier is enabled by declaring an assembly that is marked as security-transparent.

我推测,EF 6.x 使用泛型类型,因此会导致问题。

解决方法是使用 Entity Framework 5.0。而不是 Entity Framework 6.x。

关于c# - WCF 数据服务的 VerificationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29809072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com