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/

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 select a 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 might be some .Net bug .

What could be causing this? What should I change?

+3


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.

+1


source


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

0


source







All Articles