简体   繁体   English

c# - 错误编译目标Compact Net Framework 3.5 - 方法'GetString'的重载没有'1'参数

[英]c# - error compiling targeting Compact Net Framework 3.5 - No overload for method 'GetString' takes '1' arguments

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. 背景:我正在VB.NET中编写一个Windows Mobile软件,其中任务需要连接到邮件服务器以发送和检索电子邮件。 As a result, I also need a Mime-parser (for decoding and encoding) the e-mails in order to get the attachments. 因此,我还需要一个Mime解析器(用于解码和编码)电子邮件以获取附件。 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. 首先我想,我会写一个小的“hack”来处理这个问题(使用普通的字符串解析),但后来我在CodeProject看到了一个用C#编写的项目,我认为我会在我的解决方案中实现。 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. 我对C#了解不多,所以我只是从类中创建了一个类库,并在我的VB.NET项目中使用它。 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. 当我在普通的Windows计算机上瞄准Net Framework时,这个库运行得非常好,但当我打算制作针对Compact Net Framework的同一个库时,我遇到了麻烦。 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. 这是很自然的,因为Compact Net Framework有更多的限制,但实际上我没有得到那么多错误 - 只有两个错误,尽管在代码中的不同位置重复。

One of the errors is the one cited in the subject of this question ie "No overload for method 'GetString' takes '1' arguments". 其中一个错误是在这个问题的主题中引用的错误,即“方法'没有重载'GetString'取'1'参数”。 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: 如上所述,我对C#了解不多,所以我将带有错误的类转换为VB-NET,但我仍然不太了解..这是给出上述错误的函数:

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. 如果这个类需要完整的源代码,那么我可以在这个帖子中的另一个消息中发布它,或者你可以通过在上面提到的网站上下载代码并查看名为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 Rgds,moster67

CF .NET要求您使用签名:Encoding.GetString方法(array [],Int32索引,Int32计数),所以尝试使用:

...GetString(b, 0, b.Length);

If you look up the Encoding class on MSDN you'll find information about the availability of methods in the compact framework. 如果在MSDN上查找Encoding类,您将在紧凑框架中找到有关方法可用性的信息。

http://msdn.microsoft.com/en-us/library/system.text.encoding.default.aspx 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. 在您的情况下,.NET Compact Framework 3.5,2.0,1.0支持System.Text.Encoding.Default属性,因此您应该全部设置。

But here is the thing. 但事情就是这样。 MS sometimes drop's of methods from the class implementation, or to be precise overloads. MS有时从类实现中删除方法,或者精确地重载。

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. 查看文档http://msdn.microsoft.com/en-us/library/system.text.encoding.getstring.aspx,您可以通过查看.NET Compact中的图标(左侧的小图像)来判断Framework支持编码类,删除了一些重载。

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. 将byte []数组传递给GetString方法时,它无法找到该重载,因此您必须添加int offset和int count。

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. 尝试使用字节数组,起始索引和计数的重载,并将0作为起始索引,将b.Length作为长度。

Thanks to Michael, John and Rune for replying to my question. 感谢Michael,John和Rune回答我的问题。 By using your suggestions, I resolved the problem and I managed to compile/build the library targeting the CF.NET 3.5. 通过使用您的建议,我解决了问题,并设法编译/构建面向CF.NET 3.5的库。 Thanks also to ctacke for editing my question and making it more readable. 还要感谢ctacke编辑我的问题并使其更具可读性。

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: BTW,正如我在第一篇文章中提到的,我有另一个问题,我打算在另一个线程中询问,哪个不允许我为CF.NET构建库,即行:

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

In this case, the problem is that the CF.NET does not recognize "BodyName". 在这种情况下,问题是CF.NET不识别“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). 我找不到任何替代方法或变通方法来获取所使用的字符集(BodyName检索此信息),所以最后我只是为它分配了一个固定值(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). 在任何情况下,对我来说这已经足够,因为我的应用程序不关心文本消息 - 它使用电子邮件发送和获取附件(类似于Gmail驱动器,但与我自己的提供商)。

Thank you once again. 再一次感谢你。

Kind regards, moster67 亲切的问候,moster67

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM