private static string ComposeErrorMessage(WebResponse webResponse, string uri)
{
string message = String.Format(
CultureInfo.InvariantCulture,
"Failed to retrieve tile from this uri:\n{0}\n.An image was expected but the received type was '{1}'.",
uri,
webResponse.ContentType
);
if (webResponse.ContentType.StartsWith("text", StringComparison.OrdinalIgnoreCase))
{
using (Stream stream = webResponse.GetResponseStream())
{
message += String.Format(CultureInfo.InvariantCulture,
"\nThis was returned:\n{0}", ReadAllText(stream));
}
}
return message;
}