471,318 Members | 3,236 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

problem with Convert.FromBase64String function

I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using the
Convert.FromBase64String function but get the following error.

Invalid length for a Base-64 char array

The same code works ok if I call it from an asp.net client. In that client I
am just passing the parameter through as a standard string. Any ideas why
the same is not working from the vb6 client?

--
Scott
Dec 21 '05 #1
5 9027
Could you attach your code?
Dec 21 '05 #2
scottrm <sc*****@newsgroup.nospam> wrote:
I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using the
Convert.FromBase64String function but get the following error.

Invalid length for a Base-64 char array

The same code works ok if I call it from an asp.net client. In that client I
am just passing the parameter through as a standard string. Any ideas why
the same is not working from the vb6 client?


It sounds like you're not actually getting the same string. Check
whether you're getting a rogue null termination character at the end of
the string.

I suggest you dump out the string in both the working and non-working
versions and compare them *very* carefully. (Compare the lengths
first!). See
http://www.pobox.com/~skeet/csharp/strings.html
for some code you can grab to help you dump the strings out in a useful
way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 21 '05 #3
Thanks for the reply, the strings did seem to be different, by one character,
the string from the vb6 client seemed to have a blank character (U+0020)
where there should have been a + symbol (U+002b). Any ideas on why this is
happening?

Have a good Christmas!
--
Scott
"Jon Skeet [C# MVP]" wrote:
scottrm <sc*****@newsgroup.nospam> wrote:
I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using the
Convert.FromBase64String function but get the following error.

Invalid length for a Base-64 char array

The same code works ok if I call it from an asp.net client. In that client I
am just passing the parameter through as a standard string. Any ideas why
the same is not working from the vb6 client?


It sounds like you're not actually getting the same string. Check
whether you're getting a rogue null termination character at the end of
the string.

I suggest you dump out the string in both the working and non-working
versions and compare them *very* carefully. (Compare the lengths
first!). See
http://www.pobox.com/~skeet/csharp/strings.html
for some code you can grab to help you dump the strings out in a useful
way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 23 '05 #4
Just to clarify on this, in the vb code the string is being declared
correctly with the "+" symbol in it. It is on the transfer of the string into
the c# web service that things seem to be going wrong.
--
Scott
"scottrm" wrote:
Thanks for the reply, the strings did seem to be different, by one character,
the string from the vb6 client seemed to have a blank character (U+0020)
where there should have been a + symbol (U+002b). Any ideas on why this is
happening?

Have a good Christmas!
--
Scott
"Jon Skeet [C# MVP]" wrote:
scottrm <sc*****@newsgroup.nospam> wrote:
I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using the
Convert.FromBase64String function but get the following error.

Invalid length for a Base-64 char array

The same code works ok if I call it from an asp.net client. In that client I
am just passing the parameter through as a standard string. Any ideas why
the same is not working from the vb6 client?


It sounds like you're not actually getting the same string. Check
whether you're getting a rogue null termination character at the end of
the string.

I suggest you dump out the string in both the working and non-working
versions and compare them *very* carefully. (Compare the lengths
first!). See
http://www.pobox.com/~skeet/csharp/strings.html
for some code you can grab to help you dump the strings out in a useful
way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 23 '05 #5
scottrm <sc*****@newsgroup.nospam> wrote:
Just to clarify on this, in the vb code the string is being declared
correctly with the "+" symbol in it. It is on the transfer of the string into
the c# web service that things seem to be going wrong.


It sounds like you're not decoding a URL parameter correctly - note
that "+" is the URL encoded form of " ".

I suggest you trace at what point the string has a space, and how it's
being transferred. If you're using the normal web service
infrastructure, it should all be dealt with for you though...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Red Devil | last post: by
4 posts views Thread by Raed Sawalha | last post: by
7 posts views Thread by BluDog | last post: by
2 posts views Thread by Tiraman :-\) | last post: by
3 posts views Thread by GeezerButler | last post: by
8 posts views Thread by lisa1987i | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.