Something else is happening to you. I just created a small sample table with id (identifier), null varbinary (MAX), non-nullable varbinary (MAX) and timestamp. Using the following code works fine, without errors.
using (var context = new TestDataContext()) { var binarySample = new BinarySample { Image = null, NonNullImage = new Binary( new byte[0] ), }; context.BinarySamples.InsertOnSubmit( binarySample ); context.SubmitChanges(); }
Where, how does this code correctly throw (and catch) an SQLException, not an ArgumentNullException.
try { using (var context = new TestDataContext()) { var binarySample2 = new BinarySample { NonNullImage = null, Image = new Binary( new byte[0] ) }; context.BinarySamples.InsertOnSubmit( binarySample2 ); context.SubmitChanges(); } } catch (SqlException e) { Console.WriteLine( e.Message ); }
Is it possible that you have a partial implementation of a class that has a SendPropertyChanging handler for a property that throws an ArgumentNullException?
EDIT : based on OP comment.
Note that you cannot assign a variable of byte type [] to the binary file directly, since it causes an implicit conversion operation and an implicit conversion will raise an ArgumentNullException. You must check if the value is null before trying to assign it, and just assign the value null if the byte [] variable is null. This seems like strange behavior to me, and I hope that they will change it in the future. The MSDN documentation indicates that some changes may occur in future versions.
source share