Sendgrid-csharp: SendGrid v3 and HTML emails - Creates bad Json

Created on 27 Jun 2016  路  13Comments  路  Source: sendgrid/sendgrid-csharp

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.

help wanted bug

Most helpful comment

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

I will test my web app tomorrow.

All 13 comments

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); }

Thanks @gliljas!

That feedback should speed the resolution of this issue.

I had the same problem

same problem!!!

Hello @gliljas, @cosaques and @georgeemr,

I believe this is fixed in v7.0.3.

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"}

@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!

I opened this issue: https://github.com/sendgrid/csharp-http-client/issues/7

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

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

Perfect, thanks!

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

I will test my web app tomorrow.

@thinkingserious Everything is ok for me too. Thanks

Was this page helpful?
0 / 5 - 0 ratings