I have inherited some code where a call like:
var test = HttpUtility.HtmlDecode("google");
causes a stackoverflow. A call to WebUtility.HtmlDecode in the same place works fine. I've Googled around but not found anything about why this might be happening.
It is not a web application - and I see MSDN says to use WebUtility in this case - but other sources say I can just add a ref to System.Web and it will work fine - e.g. C# HTMLDecode without System.Web possible? I have built a test app and the same call to HtmlDecode works fine.
The stack trace is:
System.Web.dll!System.Web.HttpRuntime.StaticInit() Unknown
System.Web.dll!System.Web.HttpRuntime.HttpRuntime() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Web.dll!System.Web.HttpRuntime.FusionInited.get() Unknown
System.Web.dll!System.Web.Compilation.BuildManager.InitializeBuildManager() Unknown
System.Web.dll!System.Web.Compilation.BuildManager.GetType(string typeName = "System.Web.Util.HttpEncoder", bool throwOnError = true, bool ignoreCase = false) Unknown
System.Web.dll!System.Web.Configuration.ConfigUtil.GetType(string typeName = "System.Web.Util.HttpEncoder", string propertyName = "encoderType", System.Configuration.ConfigurationElement configElement = {System.Web.Configuration.HttpRuntimeSection}, System.Xml.XmlNode node = null, bool checkAptcaBit = true, bool ignoreCase = false) Unknown
System.Web.dll!System.Web.Configuration.ConfigUtil.GetType(string typeName = "System.Web.Util.HttpEncoder", string propertyName = "encoderType", System.Configuration.ConfigurationElement configElement = {System.Web.Configuration.HttpRuntimeSection}, bool checkAptcaBit = true, bool ignoreCase = false) Unknown
System.Web.dll!System.Web.Configuration.ConfigUtil.GetType(string typeName = "System.Web.Util.HttpEncoder", string propertyName = "encoderType", System.Configuration.ConfigurationElement configElement = {System.Web.Configuration.HttpRuntimeSection}, bool checkAptcaBit = true) Unknown
System.Web.dll!System.Web.Configuration.ConfigUtil.GetType(string typeName = "System.Web.Util.HttpEncoder", string propertyName = "encoderType", System.Configuration.ConfigurationElement configElement = {System.Web.Configuration.HttpRuntimeSection}) Unknown
System.Web.dll!System.Web.Util.HttpEncoder.GetCustomEncoderFromConfig() Unknown
mscorlib.dll!System.Lazy<System.Web.Util.HttpEncoder>.CreateValue() Unknown
mscorlib.dll!System.Lazy<System.Web.Util.HttpEncoder>.LazyInitValue() Unknown
mscorlib.dll!System.Lazy<System.Web.Util.HttpEncoder>.Value.get() Unknown
System.Web.dll!System.Web.Util.HttpEncoder.Current.get() Unknown
System.Web.dll!System.Web.HttpUtility.HtmlDecode(string s = "Google") Unknown
I'd like to understand the source of the problem if anyone knows the answer!