diff --git a/src/SoapCore/MessageEncoder/SoapMessageEncoderDefaults.cs b/src/SoapCore/MessageEncoder/SoapMessageEncoderDefaults.cs index 35734f99..ceed14ee 100644 --- a/src/SoapCore/MessageEncoder/SoapMessageEncoderDefaults.cs +++ b/src/SoapCore/MessageEncoder/SoapMessageEncoderDefaults.cs @@ -45,7 +45,11 @@ public static bool TryValidateEncoding(Encoding encoding, out Exception exceptio public static Encoding ContentTypeToEncoding(string contentType) { - var charSet = MediaTypeHeaderValue.Parse(contentType).CharSet; + string charSetFromContentType = null; + if (MediaTypeHeaderValue.TryParse(contentType, out var mediaTypeHeaderValue)) + { + charSetFromContentType = mediaTypeHeaderValue.CharSet; + } foreach (var charSetEncoding in CharSetEncodings) { @@ -54,7 +58,7 @@ public static Encoding ContentTypeToEncoding(string contentType) continue; } - if (charSetEncoding.CharSet == charSet) + if (charSetEncoding.CharSet == charSetFromContentType) { return charSetEncoding.Encoding; }