views:

975

answers:

4

Hi again,

I actually have two questions regarding the same problem but I think it is better to separate them since I don't think they are related.

Background: I am writing a Windows Mobile software in VB.NET which among its tasks needs to connect to a mail-server for sending and retrieving e-mails. As a result, I also need a Mime-parser (for decoding and encoding) the e-mails in order to get the attachments. First I thought, I would write a small "hack" to handle this issue (using ordinary string-parsing) but then I saw a project, written in C#, at CodeProject which I thought I would implement into my solution. I don't know much about C# so I simply made a class-library out of the classes and used it in my VB.NET-project. This library works very nicely when I am targeting the Net Framework on normal windows-computers however when I was going to make the same library targeting the Compact Net Framework, I ran into troubles. This is natural since the Compact Net Framework has more limits but I actually didn't get that many errors - only two although repeated in various places in the code.

One of the errors is the one cited in the subject of this question i.e. "No overload for method 'GetString' takes '1' arguments". As mentioned above, I don't know much about C# so I converted the class with the error online into VB-NET but still I don't understand much.. Here is the function which gives above indicated error:

public virtual string DecodeToString(string s)
{
  byte[] b = DecodeToBytes(s);
  if(m_charset != null)
  {
    //ERROR ON THIS LINE
    return System.Text.Encoding.GetEncoding(m_charset).GetString(b);
  }
  else
  {
    m_charset = System.Text.Encoding.Default.BodyName;
    //ERROR ON THIS LINE
    return System.Text.Encoding.Default.GetString(b);
  }
}

If the complete source-code is needed for this class, then I can post it in another message in this thread or you can find it by downloading the code at the web-site mentioned above and by having a look at the class named MimeCode.cs.

Anyone who can help me out? Can I rewrite above function somehow to overcome this problem?

I thank you in advance for your help.

Kind regards and a Happy New Year to all of you.

Rgds, moster67

+5  A: 

CF .NET requires you to use the signature: Encoding.GetString Method (array[], Int32 index, Int32 count) so try using:

...GetString(b, 0, b.Length);
Michael Bray
+1  A: 

The compact framework probably doesn't support the overload that takes only a byte array. Try the overload that takes the byte array, a start index and a count and give it 0 as the start index and b.Length as the length.

Rune Grimstad
+2  A: 

If you look up the Encoding class on MSDN you'll find information about the availability of methods in the compact framework.

http://msdn.microsoft.com/en-us/library/system.text.encoding.default.aspx

In your case the System.Text.Encoding.Default property is supported by the .NET Compact Framework 3.5, 2.0, 1.0 so you should be all set.

But here is the thing. MS sometimes drop's of methods from the class implementation, or to be precise overloads.

Looking at the documentation http://msdn.microsoft.com/en-us/library/system.text.encoding.getstring.aspx you can tell by looking at the icons (small images to the left) that while the .NET Compact Framework supports the encoding class, some overloads got removed.

When you pass the byte[] array to the GetString method, it cannot find that overload so you have to add an int offset and int count.

John Leidegren
A: 

Thanks to Michael, John and Rune for replying to my question. By using your suggestions, I resolved the problem and I managed to compile/build the library targeting the CF.NET 3.5. Thanks also to ctacke for editing my question and making it more readable.

BTW, as mentioned in my first post, I had another problem which I meant to ask in another thread and which did not permit me to build the library for CF.NET, namely the line:

m_charset = System.Text.Encoding.Default.BodyName;

In this case, the problem is that the CF.NET does not recognize "BodyName". I couldn't find any alternative ways or workarounds to get the character-set used (BodyName retrieves this information) so at the end I simply assigned it a fixed value (iso-8859-1). This means unfortunately that the library won't handle all different character-sets out there but at least the code won't break and I was able to compile it. In any case, for me it's enough since my application does not care about the text-messages - it's using e-mails in order to send and get attachments (similar to Gmail-drive but with my own provider).

Thank you once again.

Kind regards, moster67

moster67
Why didn't you post the other question?
configurator
'cause it was another case where a method was not supported by the CF.NET. Also the class is in C# and would give me few possibilites to change it since my knowledge of C# is nearly null. So, I just gave the charset a fixed value which resolved my problem - actually at the end I assigend it to utf-8
moster67