Binary Null test problem

29 views
Skip to first unread message

Thomas Glaser

unread,
Nov 14, 2009, 9:28:24 AM11/14/09
to DbLinq
Hi,

The following method in src/DbLinq/Data/Linq/Sugar/
ParameterizedQuery.cs seems to cause a problem on Mono 2.4.2.3:

private object NormalizeDbType(object value)
{
System.Data.Linq.Binary b = value as System.Data.Linq.Binary;
if (b != null)
return b.ToArray();
return value;
}

The line "if (b != null)" causes a "System.NotImplementedException".
"value" contained a string. This is quite probably a bug in Mono, but
until it is investigated / fixed I propose the following change which
solves the issue on my system by making the null check implicitly part
of an "is" test:

--- src/DbLinq/Data/Linq/Sugar/ParameterizedQuery.cs (revision 1271)
+++ src/DbLinq/Data/Linq/Sugar/ParameterizedQuery.cs (working copy)
@@ -73,12 +73,8 @@

private object NormalizeDbType(object value)
{
- if (value is System.Data.Linq.Binary)
- {
- System.Data.Linq.Binary b = value as
System.Data.Linq.Binary;
- if (b != null)
- return b.ToArray();
- }
+ if (value is System.Data.Linq.Binary)
+ return ((System.Data.Linq.Binary)(value)).ToArray();
return value;
}

Regards,
Thomas

Jonathan Pryor

unread,
Nov 16, 2009, 2:44:51 PM11/16/09
to dbl...@googlegroups.com
On Sat, 2009-11-14 at 06:28 -0800, Thomas Glaser wrote:
> The following method in src/DbLinq/Data/Linq/Sugar/
> ParameterizedQuery.cs seems to cause a problem on Mono 2.4.2.3:
>
> private object NormalizeDbType(object value)
> {
> System.Data.Linq.Binary b = value as System.Data.Linq.Binary;
> if (b != null)
> return b.ToArray();
> return value;
> }
>
> The line "if (b != null)" causes a "System.NotImplementedException".
> "value" contained a string. This is quite probably a bug in Mono

Upon investigating, I've found the culprits:

1. Binary overloads the operator== and operator!= operators (wtf?!).
2. Mono 2.4.2.3 doesn't have a "real" System.Data.Linq.dll (just
stubs); consequently:

[MonoTODO]
public static bool operator == (Binary binary1, Binary binary2)
{
throw new NotImplementedException ();
}
3. When mono shows stack traces, it's apparently now showing
the operator== in the stack trace (possibly because of inlining).

Thus, the 'value as Binary' works, and is null, but
Binary.op_Equality(b, null) throws a NotImplementedException, which is
what you see. The fix of using 'is' + 'as' works around this, as it
completely skips the Binary.op_Equality() call.

I never thought I'd hate an overloaded operator==()...

Consequently, the simple fix should be to avoid the problematic
operator==():

var b = value as Binary;
// Mono 2.4.2.3's Binary.operator!= is bad; avoid it.
if (!object.ReferenceEquals(b, null))
return b.ToArray();
return value;

Does that work for you?

- Jon


Thomas Glaser

unread,
Nov 16, 2009, 6:45:25 PM11/16/09
to DbLinq

Happy with that.

Thomas
Reply all
Reply to author
Forward
0 new messages