<p>It'd be really nice to target my Windows Forms app to the .NET 3.5 SP1 <em>client</em> framework. But, right now I'm using the <code>HttpUtility.HtmlDecode</code> and <code>HttpUtility.UrlDecode</code> functions, and the MSDN documentation doesn't point to any alternatives inside of, say, System.Net or something.</p>

<p>So, short from reflectoring the source code and copying it into my assembly---which I don't think would be worth it---are there alternatives inside of the .NET 3.5 SP1 client framework that you know of, to replace this functionality? It seems a bit strange that they'd restrict these useful functions to server-only code.</p>

[{'answer_id': 36359, 'author': 'Jeremy McGee', 'author_id': 3546, 'author_profile': 'https://Stackoverflow.com/users/3546', 'pm_score': 1, 'selected': False, 'text': '<p>The <em>.NET 3.5 SP1 Client Profile Setup Package</em> is the "cut down" version of .NET that only includes what Microsoft perceive to be the "useful" bits of .NET for client applications. So, useful things like the <code>HttpUtility</code> classes are missing.</p>\n\n<p>For more on that see <a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx" rel="nofollow noreferrer">ScottGu\'s blog</a>, search for "Client Profile Setup Package".</p>\n\n<p>To get around this you could always extract <code>System.Web.dll</code> from the GAC (it\'ll be in <code>c:\\windows\\Microsoft.NET\\Framework\\ ...</code> ) and deploy it with your application. You will, however, need to track updates and service packs as you deploy. </p>\n\n<p>Better might be to take the hit of the full .NET Framework deployment.</p>\n'}, {'answer_id': 36541, 'author': 'Andrei Rînea', 'author_id': 1796, 'author_profile': 'https://Stackoverflow.com/users/1796', 'pm_score': 0, 'selected': False, 'text': '<p>Two main ways :</p>\n\n<ol>\n<li>Deploy using the full .NET Framework</li>\n<li>Write your own / 3rd party lib for these functionalities</li>\n</ol>\n'}, {'answer_id': 36552, 'author': 'Ant', 'author_id': 3709, 'author_profile': 'https://Stackoverflow.com/users/3709', 'pm_score': 3, 'selected': True, 'text': '<p>I’d strongly not recommend rolling your own encoding. I’d use the <a href="http://www.microsoft.com/en-us/download/details.aspx?id=43126" rel="nofollow noreferrer">Microsoft Anti-Cross Site Scripting Library</a> which is very small (v1.5 is ~30kb) if HttpUtility.HtmlEncode isn’t available.</p>\n\n<p>As for decoding, maybe you could use the decoding routine from <a href="http://www.koders.com/csharp/fid1A50096D8FA38302680B0EEDAC5B1CE1AEA855D0.aspx?s=%22Lawrence+Pit%22" rel="nofollow noreferrer">Mono</a>? </p>\n'}, {'answer_id': 4389349, 'author': 'Ken Davis', 'author_id': 535211, 'author_profile': 'https://Stackoverflow.com/users/535211', 'pm_score': 3, 'selected': False, 'text': '<p>I reverse engineered the Microsoft System.Net.WebUtility class from .NET 4.0 using Reflector (I think they\'d be ok with it given the circumstances).  So you could either use .NET 4.0 Client Framework (which now has this new class) or use the code here.</p>\n\n<p>As long as you use a strong name on your assembly etc., you\'ll be safe enough.  Here:</p>\n\n<pre><code>/// &lt;summary&gt;\n///     Taken from System.Net in 4.0, useful until we move to .NET 4.0 - needed for Client Profile\n/// &lt;/summary&gt;\npublic static class WebUtility\n{\n    // Fields\n    private static char[] _htmlEntityEndingChars = new char[] { \';\', \'&amp;\' };\n\n    // Methods\n    public static string HtmlDecode(string value)\n    {\n        if (string.IsNullOrEmpty(value))\n        {\n            return value;\n        }\n        if (value.IndexOf(\'&amp;\') &lt; 0)\n        {\n            return value;\n        }\n        StringWriter output = new StringWriter(CultureInfo.InvariantCulture);\n        HtmlDecode(value, output);\n        return output.ToString();\n    }\n\n    public static void HtmlDecode(string value, TextWriter output)\n    {\n        if (value != null)\n        {\n            if (output == null)\n            {\n                throw new ArgumentNullException("output");\n            }\n            if (value.IndexOf(\'&amp;\') &lt; 0)\n            {\n                output.Write(value);\n            }\n            else\n            {\n                int length = value.Length;\n                for (int i = 0; i &lt; length; i++)\n                {\n                    char ch = value[i];\n                    if (ch == \'&amp;\')\n                    {\n                        int num3 = value.IndexOfAny(_htmlEntityEndingChars, i + 1);\n                        if ((num3 &gt; 0) &amp;&amp; (value[num3] == \';\'))\n                        {\n                            string entity = value.Substring(i + 1, (num3 - i) - 1);\n                            if ((entity.Length &gt; 1) &amp;&amp; (entity[0] == \'#\'))\n                            {\n                                ushort num4;\n                                if ((entity[1] == \'x\') || (entity[1] == \'X\'))\n                                {\n                                    ushort.TryParse(entity.Substring(2), NumberStyles.AllowHexSpecifier, (IFormatProvider)NumberFormatInfo.InvariantInfo, out num4);\n                                }\n                                else\n                                {\n                                    ushort.TryParse(entity.Substring(1), NumberStyles.Integer, (IFormatProvider)NumberFormatInfo.InvariantInfo, out num4);\n                                }\n                                if (num4 != 0)\n                                {\n                                    ch = (char)num4;\n                                    i = num3;\n                                }\n                            }\n                            else\n                            {\n                                i = num3;\n                                char ch2 = HtmlEntities.Lookup(entity);\n                                if (ch2 != \'\\0\')\n                                {\n                                    ch = ch2;\n                                }\n                                else\n                                {\n                                    output.Write(\'&amp;\');\n                                    output.Write(entity);\n                                    output.Write(\';\');\n                                    goto Label_0117;\n                                }\n                            }\n                        }\n                    }\n                    output.Write(ch);\n                Label_0117: ;\n                }\n            }\n        }\n    }\n\n    public static string HtmlEncode(string value)\n    {\n        if (string.IsNullOrEmpty(value))\n        {\n            return value;\n        }\n        if (IndexOfHtmlEncodingChars(value, 0) == -1)\n        {\n            return value;\n        }\n        StringWriter output = new StringWriter(CultureInfo.InvariantCulture);\n        HtmlEncode(value, output);\n        return output.ToString();\n    }\n\n    public static unsafe void HtmlEncode(string value, TextWriter output)\n    {\n        if (value != null)\n        {\n            if (output == null)\n            {\n                throw new ArgumentNullException("output");\n            }\n            int num = IndexOfHtmlEncodingChars(value, 0);\n            if (num == -1)\n            {\n                output.Write(value);\n            }\n            else\n            {\n                int num2 = value.Length - num;\n                fixed (char* str = value)\n                {\n                    char* chPtr = str;\n                    char* chPtr2 = chPtr;\n                    while (num-- &gt; 0)\n                    {\n                        chPtr2++;\n                        output.Write(chPtr2[0]);\n                    }\n                    while (num2-- &gt; 0)\n                    {\n                        chPtr2++;\n                        char ch = chPtr2[0];\n                        if (ch &lt;= \'&gt;\')\n                        {\n                            switch (ch)\n                            {\n                                case \'&amp;\':\n                                    {\n                                        output.Write("&amp;amp;");\n                                        continue;\n                                    }\n                                case \'\\\'\':\n                                    {\n                                        output.Write("&amp;#39;");\n                                        continue;\n                                    }\n                                case \'"\':\n                                    {\n                                        output.Write("&amp;quot;");\n                                        continue;\n                                    }\n                                case \'&lt;\':\n                                    {\n                                        output.Write("&amp;lt;");\n                                        continue;\n                                    }\n                                case \'&gt;\':\n                                    {\n                                        output.Write("&amp;gt;");\n                                        continue;\n                                    }\n                            }\n                            output.Write(ch);\n                            continue;\n                        }\n                        if ((ch &gt;= \'\\x00a0\') &amp;&amp; (ch &lt; \'Ā\'))\n                        {\n                            output.Write("&amp;#");\n                            output.Write(((int)ch).ToString(NumberFormatInfo.InvariantInfo));\n                            output.Write(\';\');\n                        }\n                        else\n                        {\n                            output.Write(ch);\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    private static unsafe int IndexOfHtmlEncodingChars(string s, int startPos)\n    {\n        int num = s.Length - startPos;\n        fixed (char* str = s)\n        {\n            char* chPtr = str;\n            char* chPtr2 = chPtr + startPos;\n            while (num &gt; 0)\n            {\n                char ch = chPtr2[0];\n                if (ch &lt;= \'&gt;\')\n                {\n                    switch (ch)\n                    {\n                        case \'&amp;\':\n                        case \'\\\'\':\n                        case \'"\':\n                        case \'&lt;\':\n                        case \'&gt;\':\n                            return (s.Length - num);\n\n                        case \'=\':\n                            goto Label_0086;\n                    }\n                }\n                else if ((ch &gt;= \'\\x00a0\') &amp;&amp; (ch &lt; \'Ā\'))\n                {\n                    return (s.Length - num);\n                }\n            Label_0086:\n                chPtr2++;\n                num--;\n            }\n        }\n        return -1;\n    }\n\n    // Nested Types\n    private static class HtmlEntities\n    {\n        // Fields\n        private static string[] _entitiesList = new string[] { \n        "\\"-quot", "&amp;-amp", "\'-apos", "&lt;-lt", "&gt;-gt", "\\x00a0-nbsp", "\\x00a1-iexcl", "\\x00a2-cent", "\\x00a3-pound", "\\x00a4-curren", "\\x00a5-yen", "\\x00a6-brvbar", "\\x00a7-sect", "\\x00a8-uml", "\\x00a9-copy", "\\x00aa-ordf", \n        "\\x00ab-laquo", "\\x00ac-not", "\\x00ad-shy", "\\x00ae-reg", "\\x00af-macr", "\\x00b0-deg", "\\x00b1-plusmn", "\\x00b2-sup2", "\\x00b3-sup3", "\\x00b4-acute", "\\x00b5-micro", "\\x00b6-para", "\\x00b7-middot", "\\x00b8-cedil", "\\x00b9-sup1", "\\x00ba-ordm", \n        "\\x00bb-raquo", "\\x00bc-frac14", "\\x00bd-frac12", "\\x00be-frac34", "\\x00bf-iquest", "\\x00c0-Agrave", "\\x00c1-Aacute", "\\x00c2-Acirc", "\\x00c3-Atilde", "\\x00c4-Auml", "\\x00c5-Aring", "\\x00c6-AElig", "\\x00c7-Ccedil", "\\x00c8-Egrave", "\\x00c9-Eacute", "\\x00ca-Ecirc", \n        "\\x00cb-Euml", "\\x00cc-Igrave", "\\x00cd-Iacute", "\\x00ce-Icirc", "\\x00cf-Iuml", "\\x00d0-ETH", "\\x00d1-Ntilde", "\\x00d2-Ograve", "\\x00d3-Oacute", "\\x00d4-Ocirc", "\\x00d5-Otilde", "\\x00d6-Ouml", "\\x00d7-times", "\\x00d8-Oslash", "\\x00d9-Ugrave", "\\x00da-Uacute", \n        "\\x00db-Ucirc", "\\x00dc-Uuml", "\\x00dd-Yacute", "\\x00de-THORN", "\\x00df-szlig", "\\x00e0-agrave", "\\x00e1-aacute", "\\x00e2-acirc", "\\x00e3-atilde", "\\x00e4-auml", "\\x00e5-aring", "\\x00e6-aelig", "\\x00e7-ccedil", "\\x00e8-egrave", "\\x00e9-eacute", "\\x00ea-ecirc", \n        "\\x00eb-euml", "\\x00ec-igrave", "\\x00ed-iacute", "\\x00ee-icirc", "\\x00ef-iuml", "\\x00f0-eth", "\\x00f1-ntilde", "\\x00f2-ograve", "\\x00f3-oacute", "\\x00f4-ocirc", "\\x00f5-otilde", "\\x00f6-ouml", "\\x00f7-divide", "\\x00f8-oslash", "\\x00f9-ugrave", "\\x00fa-uacute", \n        "\\x00fb-ucirc", "\\x00fc-uuml", "\\x00fd-yacute", "\\x00fe-thorn", "\\x00ff-yuml", "Œ-OElig", "œ-oelig", "Š-Scaron", "š-scaron", "Ÿ-Yuml", "ƒ-fnof", "ˆ-circ", "˜-tilde", "Α-Alpha", "Β-Beta", "Γ-Gamma", \n        "Δ-Delta", "Ε-Epsilon", "Ζ-Zeta", "Η-Eta", "Θ-Theta", "Ι-Iota", "Κ-Kappa", "Λ-Lambda", "Μ-Mu", "Ν-Nu", "Ξ-Xi", "Ο-Omicron", "Π-Pi", "Ρ-Rho", "Σ-Sigma", "Τ-Tau", \n        "Υ-Upsilon", "Φ-Phi", "Χ-Chi", "Ψ-Psi", "Ω-Omega", "α-alpha", "β-beta", "γ-gamma", "δ-delta", "ε-epsilon", "ζ-zeta", "η-eta", "θ-theta", "ι-iota", "κ-kappa", "λ-lambda", \n        "μ-mu", "ν-nu", "ξ-xi", "ο-omicron", "π-pi", "ρ-rho", "ς-sigmaf", "σ-sigma", "τ-tau", "υ-upsilon", "φ-phi", "χ-chi", "ψ-psi", "ω-omega", "ϑ-thetasym", "ϒ-upsih", \n        "ϖ-piv", "\u2002-ensp", "\u2003-emsp", "\u2009-thinsp", "\u200c-zwnj", "\u200d-zwj", "\u200e-lrm", "\u200f-rlm", "–-ndash", "—-mdash", "‘-lsquo", "’-rsquo", "‚-sbquo", "“-ldquo", "”-rdquo", "„-bdquo", \n        "†-dagger", "‡-Dagger", "•-bull", "…-hellip", "‰-permil", "′-prime", "″-Prime", "‹-lsaquo", "›-rsaquo", "‾-oline", "⁄-frasl", "€-euro", "ℑ-image", "℘-weierp", "ℜ-real", "™-trade", \n        "ℵ-alefsym", "←-larr", "↑-uarr", "→-rarr", "↓-darr", "↔-harr", "↵-crarr", "⇐-lArr", "⇑-uArr", "⇒-rArr", "⇓-dArr", "⇔-hArr", "∀-forall", "∂-part", "∃-exist", "∅-empty", \n        "∇-nabla", "∈-isin", "∉-notin", "∋-ni", "∏-prod", "∑-sum", "−-minus", "∗-lowast", "√-radic", "∝-prop", "∞-infin", "∠-ang", "∧-and", "∨-or", "∩-cap", "∪-cup", \n        "∫-int", "∴-there4", "∼-sim", "≅-cong", "≈-asymp", "≠-ne", "≡-equiv", "≤-le", "≥-ge", "⊂-sub", "⊃-sup", "⊄-nsub", "⊆-sube", "⊇-supe", "⊕-oplus", "⊗-otimes", \n        "⊥-perp", "⋅-sdot", "⌈-lceil", "⌉-rceil", "⌊-lfloor", "⌋-rfloor", "〈-lang", "〉-rang", "◊-loz", "♠-spades", "♣-clubs", "♥-hearts", "♦-diams"\n     };\n        private static Dictionary&lt;string, char&gt; _lookupTable = GenerateLookupTable();\n\n        // Methods\n        private static Dictionary&lt;string, char&gt; GenerateLookupTable()\n        {\n            Dictionary&lt;string, char&gt; dictionary = new Dictionary&lt;string, char&gt;(StringComparer.Ordinal);\n            foreach (string str in _entitiesList)\n            {\n                dictionary.Add(str.Substring(2), str[0]);\n            }\n            return dictionary;\n        }\n\n        public static char Lookup(string entity)\n        {\n            char ch;\n            _lookupTable.TryGetValue(entity, out ch);\n            return ch;\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 4480633, 'author': 'Almund', 'author_id': 479632, 'author_profile': 'https://Stackoverflow.com/users/479632', 'pm_score': 5, 'selected': False, 'text': '<p>Found today from <a href="http://10rem.net/blog/2010/04/07/encoding-decoding-uris-and-html-in-the-net-4-client-profile?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+PeteBrown-ASPNET+%28Pete+Brown%27s+Blog+%3A+ASP.NET%29" rel="noreferrer">this here little site</a> that HtmlEncode/Decode can be done using System.Net library in C# 4.0 Client Profile:</p>\n\n<pre><code>Uri.EscapeDataString(...)\nWebUtility.HtmlEncode(...)\n</code></pre>\n\n<p>Edit: I re-read that the question applied for the 3.5 Client Framework but maybe this can be useful those who have updated 4.0..</p>\n'}, {'answer_id': 8517661, 'author': 'coolaj86', 'author_id': 151312, 'author_profile': 'https://Stackoverflow.com/users/151312', 'pm_score': 2, 'selected': False, 'text': "<p>Apparently google couldn't find it either, so they wrote there own api-compatible version:</p>\n\n<p>Here's a workaround:</p>\n\n<ol>\n<li><p>Compile Google's version as a library</p>\n\n<pre><code>wget 'http://google-gdata.googlecode.com/svn/trunk/clients/cs/src/core/HttpUtility.cs'\ngmcs -t:library HttpUtility.cs\n</code></pre></li>\n<li><p>Edit <code>your-project.cs</code> to include that namespace</p>\n\n<pre><code>using Google.GData.Client; // where HttpUtility lives\n</code></pre></li>\n<li><p>Recompile using the library</p>\n\n<pre><code>gmcs your-project.cs -r:System.Web.Services -r:System.Web -r:HttpUtility\n</code></pre></li>\n</ol>\n\n<p>From glancing at the source code, it appears that this is <code>.NET 2.0</code>-compatible.</p>\n\n<p>I just wrote my first hello world in csharp yesterday and I ran into this problem, so I hope this helps someone else.</p>\n"}, {'answer_id': 12789657, 'author': 'hfrmobile', 'author_id': 254829, 'author_profile': 'https://Stackoverflow.com/users/254829', 'pm_score': 2, 'selected': False, 'text': "<p>When addressing <strong>Windows Phone</strong> <em>and</em> the <strong>Desktop</strong> (Client profile!) world the fastest way I found is:</p>\n\n<pre><code>        private static string HtmlDecode(string text)\n        {\n#if WINDOWS_PHONE\n            return System.Net.HttpUtility.HtmlDecode(text);\n#else\n            return System.Net.WebUtility.HtmlDecode(text);\n#endif\n        }\n</code></pre>\n\n<p>The odd thing for me was that the namespace is <strong>System.Net</strong> but the class name differs in the <strong>Windows Phone</strong> world ... (don't like to use System.Web/full profile when not really needed and the System.Web isn't supported on the Windows Phone platform anyway ...)</p>\n"}]
['https://Stackoverflow.com/questions/36315', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3191/']