Ask Paula!

...bringing you notes from the field...
posts - 55, comments - 17, trackbacks - 0

My Links

News

Article Categories

Archives

Post Categories

.NET Development

Enterprise Integration

Java Development

Mobile/PDA Development

Professional Affiliations

Why do I get: System.Byte[] for a String?

There are several circumstances which will display this output (or exception in some cases) in .NET, however the primary reason is because there is a mismatch between the expected format and the casting taking place in your application.  An example would be attributes which are bound to LDAP that do not readily cast to string.

Here is a quick solution (that has its roots in vc++) for successfully casting this datatype to string:

byte[] myByteArray = (byte[])result.Properties["memberOf"][counter];
string myString = "";
foreach (byte b in myByteArray)
{
    char singleChar = Convert.ToChar(b);
    myString += singleChar.ToString();
}

I just received some feedback from Joe. He was kind enough to offer alternative code:

                  byte [] bytes = Encoding.ASCII.GetBytes("This is a test");
                  String s = Encoding.ASCII.GetString(bytes);

Print | posted on Friday, January 25, 2008 11:45 AM | Filed Under [ Practical Answers ]

Feedback

Gravatar

# re: Why do I get: System.Byte[] for a String?

perhaps see post as well

http://techrookies.blogspot.com/2008/07/when-databinding-results-in-systembyte.html
7/22/2008 2:20 AM | Hamy
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: