Bug #24957 MySql.Data.Types.MySqlConversionException is not marked as Serializable.
Submitted: 11 Dec 2006 15:40 Modified: 27 Feb 2007 11:24
Reporter: John Vanderburg Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.0.2 OS:Windows (Win XP SP2)
Assigned to: CPU Architecture:Any
Tags: date, exception, remoting, time

[11 Dec 2006 15:40] John Vanderburg
Description:
When MySqlConversionException is raised in a remote object, the client application receives a SerializationException exception instead.  Information related to the actual exception is not available to the client application.

Workarounds for this problem are very easy, including:

1. Following the information in the documentation 23.2.5.6. Handling Date and Time Information in Connector/NET (http://dev.mysql.com/doc/refman/5.0/en/connector-net-using-datetime.html)

2. Handling the exception in the remote object possibly raising another exception which is remotable.

How to repeat:
Note:  This isn't very detailed and dosn't go into any detail on the issues with remoting.  The actual issue is related to .NET remoting and well documented.  If necessary I can create a sample.

1. Create a table with a date column and insert a row with a date .NET considers invalid, such as '0000-00-00'.
2. Create a class derived from MarshalByRef which uses MySQL Connector/Net to read the row.
3. Create a host program to activate the class created in step 2.
4. Create a client application to create an instance of the remote object and call the method to read the "invalid" date.

Suggested fix:
Add [Serializable] attribute to MySqlConversionException class as follows:

In MySqlConversionException.cs:
    [Serializable]    // Add attribute
    public class MySqlConversionException : ApplicationException

Also, you may want consider the following.  It is unrelated and completely a matter of preference; however, I've read a lot about it including information straight from the people who designed the base class libraries for .NET

Change the above class to derive from System.Exception instead of ApplicationException.

See the latter part of the post below for specific info:
http://blogs.msdn.com/brada/archive/2004/03/25/96251.aspx
[2 Jan 2007 16:49] John Vanderburg
Finally had some time to do some testing.  Adding [Serializable] isn't enough.  It also requires a Serialization constructor.  The following works:

using System;
using System.Security.Permissions;
using System.Runtime.Serialization;

namespace MySql.Data.Types
{
	/// <summary>
	/// Summary description for MySqlConversionException.
	/// </summary>
    [Serializable]
	public class MySqlConversionException : ApplicationException
	{
		/// <summary>Ctor</summary>
		public MySqlConversionException(string msg)
			: base(msg)
		{
		}

        [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
        protected MySqlConversionException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }
	}
}
[2 Jan 2007 16:55] Tonci Grgin
Hi John and thanks for your problem report. For the sake of completeness, please provide following:
 - NET FW version
 - Small but complete test case presenting this error
 - MySQL server version
[4 Jan 2007 20:19] John Vanderburg
Tonci:

Sorry about that.  Here's the version info:

MySQL Server version 5.0.27-standard-log via TCP/IP
.NET version 2.0.50727

I'll come up with a short program to reproduce the error.  I think I can do it using application domains so you won't have to mess with any remoting set issues.  I many not be able to get to it until next week, but again the issue isn't critical.

Thanks
[5 Jan 2007 7:46] Tonci Grgin
OK John, I'm waiting. It is realy hard to tell what's going on without proper test case since, sometimes, one can use choose execution paths/environments not exhibiting error at all.
[9 Jan 2007 3:59] John Vanderburg
Programs to recreate issue.

Attachment: bug-24957-example.txt (text/plain), 6.89 KiB.

[9 Jan 2007 4:07] John Vanderburg
Tonci:

I've attached a file with programs to recreate the issue.  Follow the instructions in the file on how to split out the two programs and compile them.

The program doesn't do any database access since the issue is with the .NET exception implementation, it just shows what happens when the MySqlConversionException is throw in a remote object.

The issue occurs in following routine of the 2nd (the exe) program.  It should catch the MySqlConversionException that is thrown in the remote application domain, but it doesn't.

Please let me know if you need anything else of have any questions.

Thanks

/// <summary>
/// Call the remote method and tell it to throw MySqlConversionException.
/// We should catch the MySqlConversionException, however, because it doesn't
/// handle serialization, we get a different exception.
/// </summary>
public void BugTest()
{
    Console.WriteLine(_divider);
    Console.WriteLine("     Test using MySqlConversionException");
    Console.WriteLine(_divider);
    try
    {
        // Invoke the method
        _remoteInstance.ThrowIt(false);
        Console.WriteLine("No exception occured in remote method.");
    }
    catch(MySqlConversionException cnvEx)
    {
        Console.WriteLine("MySqlConversionException occured in remote  method.  Message: {0}", cnvEx.Message);
    }
       catch(Exception ex)
       {
          Console.WriteLine("Other occured in remote  method.  Details: {0}", ex);
       }
    }
[15 Jan 2007 6:51] Tonci Grgin
Thanks John.
[22 Feb 2007 20:55] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/20421
[22 Feb 2007 20:56] Reggie Burnett
Fixed in 5.0.4 and 1.0.10
[22 Feb 2007 20:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/20422
[27 Feb 2007 11:24] MC Brown
A note has been added to the 5.0.4 and 1.0.10 changlogs.
[18 Jul 2016 17:49] Martin Sundquist
As per John Vanderburg's comment on 2 Jan 2007 it requires a serializable constructor, this was never pushed along with the patch and the problem still remains in the 6.9.9 source code, the new error message gotten from the partial fix is: "The constructor to deserialize an object of type 'MySql.Data.Types.MySqlConversionException' was not found.", could you reopen this bug or should I file a new one ?