Search code examples
c#asp.netwcfwcf-data-serviceswcf-binding

WCF Data Services showing error of unhandled exception


I am running a very simple program, I have ASP.NET Project in which I added WcfDataService1 file, name of the file is WcfDataService1.svc which is below:

namespace WebApplication
{
    public class WcfDataService : EntityFrameworkDataService<SampleDatabaseEntities>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    }
}

I also checked my view markup:

<%@ ServiceHost Language="C#" Debug="true" Factory="System.ServiceModel.Activation.WebServiceHostFactory, System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Service="WebApplication.WcfDataService" CodeBehind="WcfDataService.svc.cs" %>

But still its showing me below error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type 'WebApplication.WcfDataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

UPDATE:

I re-start the PC and after that its showing me below issue:

Could not load file or assembly 'Microsoft.Data.Services, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I tried many methods for it but still showing me error.

I checked in my C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics there are 5.6.2 version dlls are there, I replaced them with 5.6.4 but still getting the same error.

Solution

  • Maybe you tried uninstalling and then reinstalling the package? you can

    • clean your solution
    • delete all obj and bin directories
    • uninstall this package from the whole solution
    • ensure to delete this file in GAC: &userprofile%.nuget\packages\microsoft.data.services - make sure to delete whole directory
    • now you can install from NuGet the required version