The type 'MySqlConnection' exists in both 'MySql.Data Issue

柔情痞子 提交于 2019-12-13 12:12:16

问题


I have Referenced MySql.Data on one project and Other project referenced nuget package which also referenced MySqlConnector inside of it. projects has dependency .

when i compile application im getting this error

This is application hierarchy

is there any way to avoid this? or did i do anything wrong when referencing packages?

Thanks

UPDATE this is the same namespaces from difference libs

UPDATE 2

This is the sample repo which reproduced same issue


回答1:


In NET.Framework projects you can go to the reference properties and set an alias for assembly. Net core projects doesn't fully support yet aliases for assemblies. But there is a workaround to use aliases in .net core. Edit your csproj file like this:

<Project Sdk="Microsoft.NET.Sdk.Web">
...

  <Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'MySqlConnector'">
        <Aliases>MySqlConnectorAlias</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>
...
</Project>

then in your cs file before all usings:

extern alias MySqlConnectorAlias;

then you can reference to you type from MySqlConnector like this:

MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlConnection



回答2:


It will work If you remove mysql.data reference from Your project/references.

Hope it will work for you. for me it was worked. My project is ASP.NET Core Framework. Created project in VS2017 and opening in VS2019 at that time it introduced.



来源:https://stackoverflow.com/questions/48683241/the-type-mysqlconnection-exists-in-both-mysql-data-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!