问题
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