VerificationException with WCF Data Services

I created basic WCF Data Services with Entity Framework using .Net 4.5.2 with Entity Framework 6.1.3. There is only one table in the database.

Here is the configuration:

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 run the project, I can see this:

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


<service xmlns="" xmlns:atom="" xml:base="http://localhost:49570/MyDataService.svc/">
<collection href="DataItem">


When I select a table, I get this exception:

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


<m:error xmlns:m="">
<m:message xml:lang="en-US">An error occurred while processing this request.</m:message>
<m:message>Operation could destabilize the runtime.</m:message>
 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()


It might be some .Net bug .

What could be causing this? What should I change?


source to share

2 answers

It seems that this is indeed a bug (or at least a limiting feature).

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

When I switched to Entity Framework 5.0 , the services were working fine.

According to this KB article :

Let's assume you have upgraded from an earlier version of the .NET Framework to .NET Framework 4.5 on your computer. When you use third party controls, you might get a System.Security.VerificationException exception. This issue occurs when the following conditions are true:

  • Third party items use generic types.
  • The CLR verifier is activated by declaring an assembly that is marked as transparent for security.

I am guessing that EF 6.x uses generic types, which is why it is causing the problem.

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


source has a Nuget package which should help, but it's still in pre-release (2015/09/22).

From October 2013: "And now for some cool news: You can finally use WCF Data Services with Entity Framework 6+! Today we download a new NuGet package called WCF Services Entity Framework Provider . This NuGet package bridges the gap between data services. WCF 5.6.0 and Entity Framework 6+



All Articles