6

I have a MessageContract containing one BodyMember. When I try to send that message contract without initializing that BodyMember I get following excepton:

System.ArgumentNullException occurred Message=Value cannot be null. Parameter name: FileStream

If I change it to MessageHeader it will work (but I need it to stay BodyMember). Is it possible that MessageBodyMember can't null or that Stream can't be null?

This is MessageContract:

[MessageContract]
public class AdsAdminRequest : ServiceMessageRequest
{
    [MessageHeader]
    public AdsAdminCriteria Criteria { get; set; }

    [MessageHeader]
    public AdDto Ad { get; set; }

    [MessageBodyMember]
    public Stream FileStream { get; set; }
}
mersadk
  • 337
  • 5
  • 19

1 Answers1

12

Stream is a special case which means "everything in the message body". If you really want to send null (or Nothing), consider passing Stream.Null.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • -1: According to the linked question, Stream.Null is not for returning in case of an error. Instead, one should consider throwing a custom-made FaultException that includes information and is caught, instead of returning a proxy value. – Manuel Hoffmann Oct 17 '18 at 12:02