Connecting Tech Pros Worldwide Forums | Help | Site Map

problem with Convert.FromBase64String function

scottrm
Guest
 
Posts: n/a
#1: Dec 21 '05
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

Ben Dewey
Guest
 
Posts: n/a
#2: Dec 21 '05

re: problem with Convert.FromBase64String function


Could you attach your code?


Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#3: Dec 21 '05

re: problem with Convert.FromBase64String function


scottrm <scottrm@newsgroup.nospam> wrote:[color=blue]
> 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?[/color]

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 - <skeet@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
scottrm
Guest
 
Posts: n/a
#4: Dec 23 '05

re: problem with Convert.FromBase64String function


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:
[color=blue]
> scottrm <scottrm@newsgroup.nospam> wrote:[color=green]
> > 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?[/color]
>
> 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 - <skeet@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
>[/color]
scottrm
Guest
 
Posts: n/a
#5: Dec 23 '05

re: problem with Convert.FromBase64String function


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:
[color=blue]
> 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:
>[color=green]
> > scottrm <scottrm@newsgroup.nospam> wrote:[color=darkred]
> > > 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?[/color]
> >
> > 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 - <skeet@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
> >[/color][/color]
Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#6: Dec 23 '05

re: problem with Convert.FromBase64String function


scottrm <scottrm@newsgroup.nospam> wrote:[color=blue]
> 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.[/color]

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 - <skeet@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
Closed Thread