MySQL 在 Finalize 中抛出 NullReferenceException...您如何处理这个问题?
我在 64 位 Windows 上使用 MySQL 和 .Net 连接器。由于某种原因,Mysql 在 Finalize 中抛出 NullReferenceException。这是此处的问题,似乎是由于错误造成的此处进行了描述。这个错误是在 6.22 中报告的,但我在 6.23 中也遇到了这个问题,所以显然它没有得到修复。
我将 MySQL 与帮助程序类一起使用,并通过实例化连接和 Mysqlcommand 对象。
有谁知道我需要更改代码的哪一部分来解决这个问题?因为即使这是 Mysql 中的一个错误,但这并不普遍,因为我在其他项目中没有遇到这个问题。 MySQL 错误报告也没有关于如何重现它的详细信息。
有什么建议吗?
I am using MySQL with the .Net connector on 64 bit Windows. For some reason Mysql is throwing a NullReferenceException in Finalize. This is the problem here and it seems that its due to a bug described here. This bug was reported in 6.22, but I am getting the issue with 6.23 too so apparently it is not fixed.
I am using MySQL both with the helper classes, and by instantiating the connection and the Mysqlcommand object.
Does anybody have any idea what part of my code do I need to change to fix this issue? Cause even though this is a bug in Mysql this is not universal because I am not getting the problem in my other projects. MySQL bug report has no details on how to reproduce it either.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在
MySqlConnection
上调用Dispose
(或将其包装在using
中),那么理论上不应调用终结器,至少在>MySqlConnection
已正确实施。如果你这样做并且它仍然被调用,你必须查看源代码并看看它是否做了任何有用的事情。如果没有,您可以对其调用
GC.SuppressFinalize()
。如果是,您可以子类化 MySqlConnection,重写其 Finalize() 方法并吞掉基本方法抛出的异常。显然,这两种方法都是主要黑客,并且只是解决方法,而不是修复。If you call
Dispose
on theMySqlConnection
(or wrap it inusing
) then in theory the finalizer should not be called, at least ifMySqlConnection
was implemented properly.If you are doing that and it's still called you'd have to have a look at the source code and see if it's doing anything useful. If not, you could call
GC.SuppressFinalize()
on it. If it is, you could subclassMySqlConnection
, override itsFinalize()
method and swallow the exception thrown by the base method. Obviously, both of those approaches are major hacks and are only workarounds, not fixes.什么有效:我确实怀疑 MySQL 连接没有像应有的那样很好地实现 MySql 读取器,但我不确定。在Evegeny的回答之后,我决定进行更深入的检查。因此,我安装了那个很棒的软件 Reflector Pro 的演示版本,并直接深入研究了 MySQL 数据连接器的源代码,这确实是 MySQL 数据连接器中的一个错误。
摆脱用于获取 MySqlDataReader 对象的 MySQL Helper,一切都会变得很酷。
谢谢叶夫根尼。
更多详细信息此处
What worked: I did suspect that MySQL connection didn't implement the MySql reader as nicely as they should have, but I wasn't sure. After Evegeny's answer I decided to do a deeper checked. So I installed the demo version of that awesome software reflector pro and drilled right into the source code of the MySQL Data Connector and it indeed is a bug in MySQL Data connector.
Get rid of the MySQL Helper for getting MySqlDataReader objects and things will be cool again.
Thanks Evgeny.
More Details here