Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.NotSupportedException: No data is available for encoding 51936 #598

Closed
sour7230 opened this issue Dec 13, 2017 · 24 comments
Closed
Labels
question A question about how to do something

Comments

@sour7230
Copy link

System.NotSupportedException: No data is available for encoding 51936. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

@jstedfast
Copy link
Owner

If you are using .NET Core, you need to register encodings.

See jstedfast/MimeKit#330

@jstedfast jstedfast added the question A question about how to do something label Dec 13, 2017
@sour7230
Copy link
Author

sour7230 commented Dec 13, 2017 via email

@jstedfast
Copy link
Owner

Can you send me a pull request to fix it properly then?

@sour7230
Copy link
Author

ssue was not resolved ,kindly check it.

image

@jstedfast
Copy link
Owner

If you want me to fix it, you need to tell me how to reproduce the problem. Start with telling me what type of project you created and how I can duplicate that (i.e. which options did you enable?).

Then tell me how you added the MailKit nuget and which MailKit assembly is being referenced (net45? netstandard? net461? a PCL?)

@jstedfast
Copy link
Owner

Or better yet, just zip up your project and send it to me (either via email or link me to a dropbox or something).

@jstedfast jstedfast changed the title Mailkit to get mail System.NotSupportedException: No data is available for encoding 51936 Dec 13, 2017
@jstedfast
Copy link
Owner

Looks like you created a Cross Platform -> Xamarin.Forms App and selected ".NET Standard" for your code-sharing strategy based on my fiddling with creating projects.

Unfortunately for you, I don't get any exceptions when creating new MimeMessages when I go to run my compiled app.

It works perfectly fine for me.

@sour7230
Copy link
Author

sour7230 commented Dec 14, 2017 via email

@jstedfast
Copy link
Owner

You need to go into your Android and iOS project's Project Options and check the checkboxes for the various charset locales:

https://www.screencast.com/t/97OxahwPrg

@sour7230
Copy link
Author

sour7230 commented Dec 15, 2017 via email

@jstedfast
Copy link
Owner

Here's the code that is somehow not catching System.NotSupportedException:

static bool ProbeCharset (int codepage)
{
	try {
		Encoding.GetEncoding (codepage);
		return true;
	} catch {
		return false;
	}
}

This seems impossible and yet it's not. This seems like a bug in Xamarin's iOS and Android runtimes, not a bug in MimeKit or MailKit.

That catch clause should be catching all exceptions, but for whatever reason, it isn't.

@jstedfast
Copy link
Owner

When I create a new Cross Platform Mobile App and select ".NET Standard" as my code-sharing option, my Android and iOS projects themselves are not ".NET Standard", but in your project, they are.

In my project, I get no exceptions when I create a new MimeMessage. In your project, you do.

I'm using the latest version of Visual Studio (15.5.2). What did you use to create your initial project from a template?

@jstedfast
Copy link
Owner

In other words, when I create a new project, I end up with the following 3 projects:

  • App# (which is .NETStandard 2.0)
  • App#.Android (which is NOT .NETStandard 2.0)
  • App#.iOS (which is NOT .NETStandard 2.0)

Your project is like this:

  • App# (which is .NETStandard 2.0)
  • App#.Android (which is .NETStandard 2.0)
  • App#.iOS (which is .NETStandard 2.0)

This is probably what is causing things to fail. I don't know how you got your current project, but I know that at least iOS does not support being built as netstandard2.0 yet (I'm not sure of android).

That's probably confusing the hell out of the Android and/or iOS runtimes and causing them to break.

@sour7230
Copy link
Author

sour7230 commented Dec 15, 2017 via email

@jstedfast
Copy link
Owner

I can't help you because the problem is not with MimeKit or MailKit, it's a problem with your setup.

You need the Android and iOS projects to not be netstandard2.0. Then it will work.

@sour7230
Copy link
Author

sour7230 commented Dec 16, 2017 via email

@sour7230
Copy link
Author

sour7230 commented Dec 23, 2017 via email

@polterguy
Copy link

polterguy commented Jun 20, 2018

Hi Jeffrey, for weird reasons, apparently out of the blue, all of a sudden, I am experiencing this exact same error. As far as I know, there's no Chinese in my code or my data. The error occurs when I try the following.

MimePart retVal = new MimePart ("application/x-hyperlambda");

System ==> .Net Fr. 4.5.2 (Mono) + MimeKit 2.0.0 and BC 1.8.1 + Mac OSX using Xamarin Studio (Visual Studio for OSX)

The weird part is that this worked perfectly fine until just now ...???

I am not using .Net Core as far as I know ...??

@jstedfast
Copy link
Owner

Which version of Mono? There was a Mono runtime bug causing this a few months ago but was fixed in either 5.8 or 5.10 (I forget which)

@polterguy
Copy link

I am not sure, I am using Visual Studio for OSX (Xamarin Studio) with .Net Fr. 4.5.2 ...

@polterguy
Copy link

Sorry, my bad - Just completely ignore that one (blush!)

@jstedfast
Copy link
Owner

In Xamarin Studio, if you go to the "Xamarin Studio" menu, click "About" and then in the About Dialog click the "Show Details" button in the lower right corner, it will give you a list of versions of all installed components.

Mono should be at the top. For example, this is what mine says at the top:

Visual Studio Enterprise 2017 for Mac (Preview)
Version 7.6 Preview (7.6 build 947)
Installation UUID: 119afeba-010d-4f09-8021-f77e92bcb3e7
Runtime:
	Mono 5.16.0.5 (2018-06/7627a5f9eeb) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 4.4.0.36 (master / 0c7c49a6)

The other possibility is that your project is referencing the netstandard nuget, but assuming that it's the the packages.config here: phosphorusfive/plugins/extras/p5.mime/packages.config

then it looks like it references the net452 framework (which matches what you've been saying), which means it should be referencing the net45 assembly (MimeKit nuget packages do not include a 4.5.2 assembly).

@polterguy
Copy link

There was another bug in my code, and I set it to break on all exceptions, and an exception (which probably) was caught stopped my debugger at that point, while it actually was a completely different bug that was the cause ...

Sorry (blush!)

I should have done more research before jumping to conclusions ... :)

Thx for the recipe of figuring out .Net version though ...

@jstedfast
Copy link
Owner

Ah, ok :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about how to do something
Projects
None yet
Development

No branches or pull requests

3 participants