views:

38

answers:

2

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?

+1  A: 

If you call Dispose on the MySqlConnection (or wrap it in using) then in theory the finalizer should not be called, at least if MySqlConnection 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 subclass MySqlConnection, override its Finalize() method and swallow the exception thrown by the base method. Obviously, both of those approaches are major hacks and are only workarounds, not fixes.

Evgeny
You could have an idea there. I am using the MySQLHelper in places which is definitely not calling dispose. Let me replace all the locations with MySQLHelper and see if that helps.
Cyril Gupta
Getting rid of MySQLHelper helped!!
Cyril Gupta
A: 

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

Cyril Gupta