Lior
Lior

Reputation: 171

Passing null for parameters in wcf results in object reference not set to an instance of an object

I trying to find a solution for this for a long time with no luck.

I have netnamedpiped srvice with the following interface

[OperationContract]
[ServiceKnownType(typeof(SubTable))]
float GetValue(Table table);

when I call it in the client with null proxy.GetValue(tbl);

I get null expcetion since the wcf can not serialise the null I wouldl like to be able to pass null with doing something like this:

if  (tbl!= null)
var result = proxyGetValue(tbl);
else
var result = proxyGetValueWhenNull();

Upvotes: 0

Views: 338

Answers (1)

Jon Lindeheim
Jon Lindeheim

Reputation: 582

Have you tried wrapping the table as a property of another class and setting the attribute [DataMember(IsRequired=false/true)]?

[DataContract]
public class TableWrapper{
    [DataMember(IsRequired=false)]
    public Table Table{get;set;}
}

[OperationContract]
[ServiceKnownType(typeof(SubTable))]
float GetValue(TableWrapper tableWrapper);

if  (tableWrapper.Table!= null)
    var result = proxyGetValue(tableWrapper.Table);
else
    var result = proxyGetValueWhenNull();

Upvotes: 1

Related Questions