473,547 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with Convert.FromBas e64String 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.FromBas e64String 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 9184
Could you attach your code?
Dec 21 '05 #2
scottrm <sc*****@newsgr oup.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.FromBas e64String 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.co m>
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*****@newsgr oup.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.FromBas e64String 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.co m>
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*****@newsgr oup.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.FromBas e64String 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.co m>
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*****@newsgr oup.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.co m>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
445
by: Red Devil | last post by:
I have a class containing string variables, hashtables..I managed to serialize it into a memory stream instead of file stream. Would like to know how can I convert the byte array to string. I tried using encoding.default.getstring but the output is an empty string..(:..damn! partial code example that copied for microsoft for testing purpose:...
4
4247
by: Raed Sawalha | last post by:
I have list of name separated by comm like this name1,name2,name3,...etc i converted then to Base-64 using Convert.ToBase64String() then pass them to webmethod then i when try to get data back to original using Convert.FromBase64String a crash generated with following error: Invalid Lenght for Base-64 char array what is the reason? the...
7
2277
by: BluDog | last post by:
Hi I am trying to store an image in an xml file, i vcan store it fine but the retreval is a bit of a problem: To String: Dim ms As New IO.MemoryStream Dim arrImage() As Byte Me.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
2
1494
by: Tiraman :-\) | last post by:
Hi Everyone, i have the following problem in my client-server Application My server take array and serialize it into the memorystream Dim ns As NetworkStream = client.GetStream() Dim writer As New IO.StreamWriter(ns) Dim bf As New BinaryFormatter Dim mem As New IO.MemoryStream
2
7133
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the French grave... Anyway when I run encryption on a plaintext word like:
0
1567
by: Andy | last post by:
Hi, I have a MS Word binary data file that is sent from my .NET webservice in response to an XMLHTTP request from an Internet Explorer client. This data has to be base64 encoded to tunnel through a firewall. I've used the .NET Convert.ToBase64String() method to encode the data. I understand that the Convert.FromBase64String only runs on...
3
11220
by: GeezerButler | last post by:
string s = "Hello"; byte abc = Convert.FromBase64String(s); This throws error "Invalid length for a Base-64 char array."?? Does anybody have any idea about how/why this happens?
3
2758
by: Steve | last post by:
I took over a web app that the developer encrypted the connection string. The connection string looks something like this )); Now, I need to change the string in the web config file, so how can I get the new connection string from plain text to the encrypted string as is currently used?
8
2610
by: lisa1987i | last post by:
I am really having trouble with encoding characters. The application I am creating i based on a NNTP component from Smilla smilla.ru My propblem is when I read a string which contain special characters and the character is set to utf-8. It works fine with iso-8859-1 strings (I think) The problem occurs whene case below is Q, encoding is...
0
7437
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7703
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7463
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.