mysql connector种类,在两个MySql.Data问题中都存在类型“ MySqlConnection”

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

WrVV8.jpg

This is application hierarchy

JQ6Ma.jpg

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

xFmFY.png

UPDATE 2

This is the sample repo which reproduced same issue

解决方案

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:

...

MySqlConnectorAlias

...

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

MySQL Connector/Net 版本所需的 .Net Framework 版本 不同的版本 MySQL Connector/Net 所需的 .Net Framework 版本也是不同的: MySQL Connector/Net 6.9.12 需要 .Net Framework 4.0 或更高版本支持。(2018-04-30, General Availability) MySQL Connector/Ne 6.10.1 需要 .Net Framework 4.5.1 或更高版本支持。 MySQL Connector Net 6.10.2 到最新的 MySQL Connector Net 8.0.20 需要 .Net Framework 4.5.2 或更高版本。 MySQL Connector/NET 6.9.12 支持与 MySQL Server 8.0.3 以及之前版本的MySQL Server连接。 从官方网站下载mysql-connector-net-8.20.0.msi安装之后,安装目录下的Assemblies中只有v4.5.2的MySql.Data.dll,也就是说它需要 v4.5.2 以上版本的 .Net Framework 支持。如果VS项目的目标框架是.NET Framework 4.5.2或更高版本,则引用正常;将项目的目标框架改为.NET Framework 4 再进行编译就会报错,提示“ 未能解析主引用“MySql.Data, Version=...... 该程序集是针对 .NETFramework,Version=v4.5.2 框架生成的......该框架版本高于当前目标框架 .NETFramework,Version=v4.0”。这表明这个 MySQL Connector/Net 的 MySql.Data.dll 需要 .Net Framework v4.5.2 的支持。 如果项目的目标框架是 .Net Framework v4.0 则最高只能使用 MySQL Connector/Net 6.9.12 的 MySql.Data.dll 。而需要注意的是 MySQL Connector/Net 6.9.12 的 MySql.Data.dll 是在2018-04-30发布的,官方文档显示支持与 MySQL Server 8.0.3 及之前的版本的MySQL Server连接。 C#通过MySql.Data.dll连接MySql数据库 在项目中引用组件:MySql.Data.dll (记得复制到本地中选择为true / 或直接把MySql.Data.dll复制到debug文件夹下) 在代码中 using MySql.Data.MySqlClient; ......接下来这里就看你表演了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值