简体   繁体   中英

VerificationException with WCF Data Services

I have created a basic WCF Data Services with Entity Framework using .Net 4.5.2 with Entity Framework 6.1.3. In the database there is only one table.

Here is the config:

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);
        }
    }

When I start the project, I can see this:

URL: http://localhost:49570/MyDataService.svc/

Content:

<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>

When I choose the table, I get this exception:

URL: http://localhost:49570/MyDataService.svc/DataItem

Content:

<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>

It could be some .Net bug .

What could cause this? What should I change?

It seems that it really is a bug (or at least a restrictive feature).

First, I used Entity Framework 6.1.3 as the database ORM, and the error was present.

When I switched back to Entity Framework 5.0 , the services worked normally.

According to this 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.

I presume, EF 6.x uses generic types so it causes the problem.

The workaround solution is to use Entity Framework 5.0. instead of Entity Framework 6.x.

http://blogs.msdn.com/b/odatateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework-6.aspx has a Nuget package that is supposed to help, but it is still in pre-release (on 2015/09/22).

From October, 2013: "And now for some exciting news: you can finally use WCF Data Services with Entity Framework 6+! Today we are uploading a new NuGet package called WCF Data Services Entity Framework Provider . This NuGet package bridges the gap between WCF Data Services 5.6.0 and Entity Framework 6+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM