passing byte[] as arg

  • Thread starter Thread starter Tim Wallace
  • Start date Start date
T

Tim Wallace

I have an array of bytes I read from a TcpClient. I need to pass that byte
array in to the constructor of an object. My code compiles, but when run, I
get a message stating: System.NullReferenceException: Object reference not
set to an instance of an object. There is data stored in the byte[], I
checked using Length. How can I pass a byte array to a method, constructor
or otherwise?

Tim
 
Tim Wallace said:
I have an array of bytes I read from a TcpClient. I need to pass that byte
array in to the constructor of an object. My code compiles, but when run,
I get a message stating: System.NullReferenceException: Object reference
not set to an instance of an object. There is data stored in the byte[], I
checked using Length. How can I pass a byte array to a method, constructor
or otherwise?

There is no mystery to passing byte[] as an argument. It's an ordinary
reference type. Your problem lies elsewhere.

David
 
I have an array of bytes I read from a TcpClient. I need to pass that byte
array in to the constructor of an object. My code compiles, but when run, I
get a message stating: System.NullReferenceException: Object reference not
set to an instance of an object. There is data stored in the byte[], I
checked using Length. How can I pass a byte array to a method, constructor
or otherwise?

I don't believe you're seeing what you think you're seeing, or the
NullReferenceException is due to something else.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Tim Wallace said:
I have an array of bytes I read from a TcpClient. I need to pass that byte
array in to the constructor of an object. My code compiles, but when run,
I get a message stating: System.NullReferenceException: Object reference
not set to an instance of an object. There is data stored in the byte[], I
checked using Length. How can I pass a byte array to a method, constructor
or otherwise?
As David said, its not the argument. Could you post the stack trace in the
exception and a short program that exhibits your problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top