WCF:无法加载文件或程序集' EntityFramework'或其中一个依赖项

时间:2016-09-01 19:58:30

标签: c# .net entity-framework wcf

我尝试构建一个在iis中托管的WCF,但是我有一个恼人的问题。

当我运行客户端控制台应用程序并连接到服务器时,我收到错误"无法加载文件或程序集' EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089&#39 ;或其中一个依赖项。"。

我的服务和客户端安装了三个nugets包。 Entityframework 6.0.0.0,MySql.data 6.9.9和MySql.Data.Entity 6.9.9。

MySql.Data.Entity要求MySql.Data高于6.8.7且EntityFramework高于或等于6.0.0.0所以我应该没问题。我很确定我在服务app.config文件中到处都引用了EF 6.0.0.0,但我仍然收到错误。

有没有人知道是否有其他原因导致这种情况?我只在我的计算机上安装了实体框架6.1.3,这可能是问题吗?

我有点陷入我的项目中,所以如果有人可以花时间帮助我,那将是非常好的!

客户项目

App.config中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IWCFProductService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:50710/ProductService" binding="basicHttpBinding" bindingConfiguration="" contract="ProductInterfaces.IWCFProductService" name="ProductServiceEndpoint" kind="" endpointConfiguration="" />
      <endpoint address="http://erihy283-pc/ProductService/Service.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCFProductService" contract="ProductService.IWCFProductService" name="BasicHttpBinding_IWCFProductService" />
    </client>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
  </entityFramework>
<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data></configuration>

服务项目

Packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.0.0" targetFramework="net452" />
  <package id="MySql.Data" version="6.9.9" targetFramework="net452" />
  <package id="MySql.Data.Entity" version="6.9.9" targetFramework="net452" />
</packages>

的App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>

  <connectionStrings>
    <add name="adventureworksEntities" connectionString="metadata=res://*/Database.csdl|res://*/Database.ssdl|res://*/Database.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=root;password=root;database=adventureworks&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

  <system.serviceModel>
    <services>
      <service name="WCFProductService" behaviorConfiguration="mexBehaviour">

        <endpoint address="ProductService"
                 binding="basicHttpBinding"
                 bindingConfiguration=""
                 name="ProductServiceEndpoint"
                 contract="ProductService.IWCFProductService"
                 behaviorConfiguration="webHttp" />

        <endpoint contract="IMetadataExchange"
                 binding="mexHttpBinding"
                 address="ProductService" />

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:50710" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
      </dependentAssembly>

      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

  </runtime>

</configuration>

主持人项目

的web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
             switchValue="Information, ActivityTracing"
             propagateActivity="true">
        <listeners>
          <add name="sdt"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData= "SdrConfigExample.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

  <system.serviceModel>

    <services>
      <service name="WCFProductService" >

        <endpoint address="ProductService"
                 binding="basicHttpBinding"
                 bindingConfiguration=""
                 name="ProductServiceEndpoint"
                 contract="ProductService.IWCFProductService"
                 behaviorConfiguration="webHttp"/>

        <endpoint address="http://localhost:50710/svc/mex"
                 binding="mexHttpBinding"
                 bindingConfiguration=""
                 contract="IMetadataExchange"/>

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:50710" />
          </baseAddresses>
        </host>

      </service>
    </services>


    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>

      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

  </system.serviceModel>

</configuration>

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.0.0" targetFramework="net452" />
  <package id="MySql.Data" version="6.9.9" targetFramework="net452" />
  <package id="MySql.Data.Entity" version="6.9.9" targetFramework="net452" />
</packages>

我在iis中设置了应用程序池ASP.NET v4.0!

1 个答案:

答案 0 :(得分:0)

错误消息通常会出现,因为您要求加载的软件包不存在。检查这一点的一种方法是查看你的&#34;包&#34;解决方案的文件夹(如果可以找到),您应该在其中看到正在使用的每个包的文件夹。这个文件夹的版本号与您要求的版本号相匹配,这一点非常重要。可能是您有EntityFramework.6.1.3而不是EntityFramework.6.0.0(您的packages.config文件要求的)。

在Visual Studio中,您可以使用程序包管理器控制台(工具 - &gt; NuGet程序包管理器 - &gt;程序包管理器控制台),并使用命令update-package EntityFramework -version 6.0.0。这应该为您更新您要求的特定版本,并使用NuGet下载软件包,如果它无法在本地找到它们。