Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Instantiate byte attribute

$
0
0

Hello

I have a method that converts a string to byte array but an ArgumentException is thrown when I try to instantiate an attribute with the value returned by the method. I get this message: "Cannot convert object of type 'System.Byte[]' to object of type 'System.String'."

I don't get why this is happening, the attribute is of type byte[] and the returned value is also a byte[]

The code is:

 byte[] bytes = GetBytes(cn.Senha);

 scsb.Password = bytes

 private byte[] GetBytes(string str)
        {
            byte[] bytes = new byte[str.Length * sizeof(char)];
            System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
            return bytes;        

        }

Please help

thanks


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>