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

SendGrid v3 and HTML emails - Creates bad Json #256

Closed
Surfrat opened this issue Jun 27, 2016 · 13 comments
Closed

SendGrid v3 and HTML emails - Creates bad Json #256

Surfrat opened this issue Jun 27, 2016 · 13 comments
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@Surfrat
Copy link

Surfrat commented Jun 27, 2016

I used the v2 API with no problems. I am now using the v3 API and I get a BadRequest response after sending. I investigated with Fiddler and I can see that the Json that is created for my email is bad.

See my problem here.

Thanks

Mark.

@thinkingserious thinkingserious added type: bug bug in the library status: help wanted requesting help from the community labels Jun 27, 2016
@gliljas
Copy link

gliljas commented Jun 27, 2016

The issue is in CSharpHttpClient/Client.cs which for no valid reason does this:

if (requestBody != null) { content = new StringContent(requestBody.ToString().Replace("'", "\""), Encoding.UTF8, MediaType); }

@thinkingserious
Copy link
Contributor

Thanks @gliljas!

That feedback should speed the resolution of this issue.

@cosaques
Copy link

I had the same problem

@georgeemr
Copy link

same problem!!!

@thinkingserious
Copy link
Contributor

Hello @gliljas, @cosaques and @georgeemr,

I believe this is fixed in v7.0.3.

@gliljas
Copy link

gliljas commented Jun 28, 2016

It solves the problem, but I strongly disagree with the solution. CSharpHttpClient still replaces single quotes with double quotes, which is has no business doing. If someone wants to use CSharpHttpClient as a generic API client, they will be surprised to find that it modifies the valid JSON.

Trust JSON.NET to do the right thing without any special escaping settings. It always produces valid JSON, such as

{"sender" : "McDonald's"}

@thinkingserious
Copy link
Contributor

@gliljas,

I recall having some issues with the JSON.NET results, that is why I implemented that hack. I believe it had something to do with this: http://stackoverflow.com/a/10679340 but I'm not sure.

I know that is not the best answer and I'll leave this ticket open so we further investigate come up with a better solution.

If you have any suggestions, please let me know.

Thank you very much for your support and for taking the time to suggest improvements!

@gliljas
Copy link

gliljas commented Jun 28, 2016

I opened this issue: sendgrid/csharp-http-client#7

...since that's where the problem is.

@thinkingserious
Copy link
Contributor

@Surfrat could you also provide the raw json that is in the image above?

@thinkingserious
Copy link
Contributor

Perfect, thanks!

@Surfrat
Copy link
Author

Surfrat commented Jun 29, 2016

Good news...
All my tests pass and the emails are sent successfully with ' in the html.

I will test my web app tomorrow.

@georgeemr
Copy link

@thinkingserious Everything is ok for me too. Thanks

@thinkingserious
Copy link
Contributor

Fixed:

Thanks to all on this thread for your continued patience!

dubrovkinmaxim pushed a commit to dubrovkinmaxim/sendgrid-csharp that referenced this issue Sep 20, 2016
dubrovkinmaxim pushed a commit to dubrovkinmaxim/sendgrid-csharp that referenced this issue Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

5 participants