5

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

enter image description here

This is application hierarchy

enter image description here

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

enter image description here

UPDATE 2

This is the sample repo which reproduced same issue

Gayan
  • 2,750
  • 5
  • 47
  • 88

2 Answers2

16

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
AlbertK
  • 11,841
  • 5
  • 40
  • 36
  • Hi Albertk, I am trying to use your suggestion in my code as: `MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlConnection mysql = new MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlConnection();`and then get the error `Cannot resolve symbole MySql`. MySql.Data.MySqlClient are all read in my case. Can you please help? Thanks – Ben Aug 17 '19 at 12:38
  • It is hard to say for sure. Are you using Resharper? If yes then try to follow answers given here: [1](https://stackoverflow.com/questions/35227523/resharper-cannot-resolve-symbol), [2](https://stackoverflow.com/questions/2678779/why-do-i-get-an-error-cannot-resolve-symbol-symbolname-in-resharper), [3](https://stackoverflow.com/questions/48654852/resharper-cannot-resolve-symbol-when-the-code-well-compiled) – AlbertK Aug 17 '19 at 17:08
1

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.

hardik patel
  • 221
  • 4
  • 8