Microsoft.Data.Services 版本问题,而 运行 WCF 数据服务

Microsoft.Data.Services version issue while running WCF Data Services

我收到以下错误:

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)

但是当我去检查我的 Packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
  <package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net472" />
  <package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net472" />
  <package id="Microsoft.Data.Services" version="5.6.4" targetFramework="net472" />
  <package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net472" />
  <package id="Microsoft.OData.EntityFrameworkProvider" version="1.0.0-beta2" targetFramework="net472" />
  <package id="System.Spatial" version="5.6.4" targetFramework="net472" />
</packages>

它显示了上面的文件,我需要更改版本吗?如果是,那么我该如何改变它?我试过 nugget 它没有用。

我查看了我的 C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics 那里有 5.6.2 版本的 dll,我用 5.6.4 替换了它们,但仍然出现相同的错误。

更新:

我在下面更新了我的web.config:

<runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Data.Services" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.6.2.0" newVersion="5.6.4.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
  </system.web>

它将输出更改为:

日志显示以下问题:

Model1.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.ThrowOnNonWarningErrors()
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest&amp;amp; providerManifest, DbProviderFactory&amp;amp; providerFactory, String&amp;amp; providerInvariantName, String&amp;amp; providerManifestToken, Memoizer`2&amp;amp; cachedCTypeFunction)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.&amp;lt;&amp;gt;c__DisplayClass5.&amp;lt;&amp;gt;c__DisplayClass7.&amp;lt;GetMetadataWorkspace&amp;gt;b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.&amp;lt;&amp;gt;c__DisplayClass5.&amp;lt;&amp;gt;c__DisplayClass7.&amp;lt;GetMetadataWorkspace&amp;gt;b__4()
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadAndCheckItemCollection[T](Func`1 itemCollectionLoader)
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.&amp;lt;&amp;gt;c__DisplayClass16.&amp;lt;.ctor&amp;gt;b__f()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required)
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace)
   at System.Data.Entity.Core.Objects.ObjectContext.InitializeMappingViewCacheFactory(DbContext owner)
   at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory)
   at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
   at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
   at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
   at lambda_method(Closure , Object )
   at System.Data.Services.Providers.DbContextHelper.GetObjectContext(Object o)
   at System.Data.Services.Caching.MetadataCache`1.TryLookup(Type serviceType, Object dataContextInstance)
   at System.Data.Services.Providers.BaseServiceProvider.LoadMetadata(Boolean skipServiceOperations)
   at System.Data.Services.Providers.EntityFrameworkDataService`1.CreateInternalProvider(Object dataSourceInstance)
   at System.Data.Services.DataService`1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider&amp;amp; metadataProviderInstance, IDataServiceQueryProvider&amp;amp; queryProviderInstance, Object&amp;amp; dataSourceInstance, Boolean&amp;amp; isInternallyCreatedProvider)
   at System.Data.Services.DataService`1.CreateProvider()
   at System.Data.Services.DataService`1.HandleRequest()
   at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody)
   at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</ExceptionString></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>262164</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2021-11-08T16:50:19.9963405Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{5ffbff76-6cbf-4bb1-a528-801615bf5b77}" /><Execution ProcessName="iisexpress" ProcessID="15812" ThreadID="8" /><Channel/><Computer>UOFL20-G0QBVN2</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>https://docs.microsoft.com/dotnet/framework/wcf/diagnostics/tracing/System-ServiceModel-Channels-MessageSent</TraceIdentifier><Description>Sent a message over a channel.</Description><AppDomain>/LM/W3SVC/3/ROOT-1-132808638175161639</AppDomain><Source>System.ServiceModel.Activation.HostedHttpContext+HostedRequestHttpOutput/42188773</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord"><MessageProperties><Encoder>ByteStreamMessageEncoder</Encoder><AllowOutputBatching>False</AllowOutputBatching></MessageProperties><MessageHeaders></MessageHeaders></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2021-11-08T16:50:19.9963405Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{5ffbff76-6cbf-4bb1-a528-801615bf5b77}" /><Execution ProcessName="iisexpress" ProcessID="15812" ThreadID="8" /><Channel/><Computer>UOFL20-G0QBVN2</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>https://docs.microsoft.com/dotnet/framework/wcf/diagnostics/tracing/System-ServiceModel-Diagno

Error: The server encountered an error processing the request. See server logs for more details

只要 WCF 服务出现任何问题,就会出现此问题。 因此,要查看有关该问题的更多详细信息,您需要在 servicedebug 标签中将 includeexceptiondetailInfaults 属性设置为 true

<Service Behavior>
 <Behavior Name="myServiceBehavior">
  <servicedebug includeexceptiondetailinfaults="true" />
 </Behavior>
</Service Behavior>

您也可以将 class 属性添加到服务 class。

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)

对于这个问题,首先检查你输出的这个dll是什么版本directory.Then

  • 清理你的解决方案
  • 删除所有obj和bin目录
  • 从整个解决方案中卸载此包
  • 确保在 GAC 中删除此文件:&userprofile%.nuget\packages\microsoft.data.services - 确保删除整个目录
  • 现在您可以从 NuGet 安装所需的版本