I am receiving an error:
“Use of unassigned local variable ‘PostData'”
when compiling the following statements below within a method. My intent is take a “string” value containing an XML SOAP header and convert it to a XMLDictionaryWriter object. See my code below:
Stream PostData;
byte[] buffer = Encoding.ASCII.GetBytes(x509.CreateX509SoapEnvelope());
PostData.Write(buffer, 0, buffer.Length); // error here
XmlDictionaryWriter xmlwriter = XmlDictionaryWriter.CreateTextWriter(PostData, Encoding.ASCII);
request.Headers.WriteHeaderContents(0,xmlwriter);
FYI, the output of x509.CreateX509SoapEnvelope() is a string and I tested that part and it works. I marked the code above to show where the error occurs.Need assistance with the error and how to fix it ?
You never assigned a value to
PostData. Thus, its default value isnulland the compiler is smart enough to tell you this is a bad thing to do (if it permitted your code as is, you will get a runtimeNullReferenceException). You need to instantiate an instance of a class that is aStream(Streamis abstract and so you need a concrete instance) and assign it toPostData.