我正在運行一個非常簡單的程式,我有 ASP.NET 專案,我在其中添加了 WcfDataService1 檔案,檔案名是 WcfDataService1.svc,如下所示:
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;
}
}
}
我還檢查了我的視圖示記:
<%@ 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" %>
但它仍然向我顯示以下錯誤:
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.
更新:
我重新啟動PC,然后它向我顯示以下問題:
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 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.
uj5u.com熱心網友回復:
也許您嘗試卸載然后重新安裝軟體包?你可以
- 清潔您的解決方案
- 洗掉所有 obj 和 bin 目錄
- 從整個解決方案中卸載此包
- 確保在 GAC 中洗掉此檔案:&userprofile%.nuget\packages\microsoft.data.services - 確保洗掉整個目錄
- 現在您可以從 NuGet 安裝所需的版本
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/421456.html
標籤:
