Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'. / Decoding a base64 string to bytes in VB.net

Posted: Tuesday 5 August 2014

With VB.net, typically trivial errors are easy to overlook, which complicates the process of software development.

As the title of this post suggests, "Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'." can be caused when you're attempting to use a function that returns a quote unquote "Byte"

This error is quite irritating because, when searched on StackOverflow, it has already been answered!

VB Value of type String cannot be converted to 1 dimensional array of Byte

With decoding base64 to bytes in VB.net, you can use the following function:

Convert.FromBase64String(_string_input_)

... where the error becomes evident

The solution to the "Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'." error is quite simple.
Just remember to dim the variable of where you are trying to push the resulting bytes to as a byte array type, aka
Dim variable As Byte()
This works as when you're defining the Byte type, you're only really defining a single byte, not an array of bytes. Think of it as defining a string as a character, where the array of bytes (
As Byte()
) is the equivalent to an array of characters (hence, being represented else-wise as a string)