无法加载文件或程序集“mysql.data”或其依赖项之一

0x6upsns  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(489)

经过充分的探索,我决定把这个问题贴在这里。我在webapi项目中遇到了这个错误,这个项目在本地iis上运行得非常好,但是当我将项目部署到我的实时服务器上时,我遇到了这个问题:无法加载文件或程序集“mysql.data”或它的某个依赖项。我正在使用mysql数据库,并在web.config文件中添加了所有相关的依赖项,但似乎没有任何结果适合我。
我的web.config文件

<?xml version="1.0" encoding="utf-8"?>
    <!--  
      http://go.microsoft.com/fwlink/?LinkId=301879
      -->
    <configuration>
      <configSections>  
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-IntranetApiDemo-20180709022909.mdf;Initial Catalog=aspnet-IntranetApiDemo-20180709022909;Integrated Security=True" providerName="System.Data.SqlClient" />        
<add name="DBCS" connectionString="Server=14.192.18.129;userid=admin;password=pwd; Database=db; convert zero datetime=True; default command timeout=0; SslMode = none" providerName="System.Data.MySqlClient" />
      </connectionStrings>
      <appSettings></appSettings>
      <system.web>
        <authentication mode="None" />
        <compilation debug="true" targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2" />
      </system.web>
      <system.webServer>
        <modules>
          <remove name="FormsAuthentication" />
        </modules>
        <handlers>
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>  
         <dependentAssembly>
            <assemblyIdentity name="MySql.Data.MySqlClient" publicKeyToken="c5687fc88969c44d" />
            <bindingRedirect oldVersion="1.0.0.0-6.10.7.0" newVersion="6.10.7.0" />
          </dependentAssembly>    
        </assemblyBinding>
      </runtime>
      <entityFramework>
       <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
        <providers>
            <provider invariantName="MySql.Data.MySqlClient"
                type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.7.0"/>
            <provider invariantName="System.Data.SqlClient"
                type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
      </entityFramework>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
    </configuration>

正如您在我上面的代码中看到的,mysql.data.entity.ef6(version=6.10.7.0)的版本与mysql.data.mysqlclient version=6.10.7.0匹配。
web.config文件中是否缺少任何内容。请帮我解决这个问题。
谢谢。

0pizxfdo

0pizxfdo1#

听起来您不应该只为设置程序集绑定重定向 MySql.Data.MySqlClient 命名空间,但也包括其父命名空间,即。 MySql.Data :

<dependentAssembly>
    <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" />
    <bindingRedirect oldVersion="1.0.0.0-6.10.7.0" newVersion="6.10.7.0" />
</dependentAssembly>

注意:在使用此绑定重定向之前,请确保 MySql.Data.dll 生产服务器中存在程序集(及其所有依赖项)&其版本与开发机器中安装的版本(6.10.7.0)匹配。
此外,mysql的连接字符串提供程序应该 MySql.Data.MySqlClient 提供程序如下:

<add name="DBCS" connectionString="Server=14.192.18.129;userid=admin;password=pwd; Database=db; convert zero datetime=True; default command timeout=0; SslMode=none" 
     providerName="MySql.Data.MySqlClient" />

参考文献:
mysql实体框架6支持

相关问题