> ## Content Index
> Fetch the complete content index at: https://blog.tsd.digital/llms.txt
> Use this file to discover other available public pages before exploring further.

# String.Format- Exception of type System.Web.HttpUnhandledException was thrown.
- URL: https://blog.tsd.digital/stringformat-exception-of-type-systemwebhttpunhandledexception-was-thrown/
- Published: 2007-08-22T19:43:12.000Z
- Updated: 2007-08-22T19:43:12.000Z
- Author: Tim Gaunt
- Tags: ASP.Net, C#, Web Development, WebDD, .Net, The Site Doctor, #Import 2025-04-01 05:36

**Type**System.FormatException**Message**Exception of type 'System.Web.HttpUnhandledException' was thrown. **StackTrace**at System.Text.StringBuilder.FormatError() at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object\[\] args) at System.String.Format(IFormatProvider provider, String format, Object\[\] args) **Error Line**0 

Just got that message (or at most "Exception of type 'System.Web.HttpUnhandledException' was thrown")? Puzzled? I was the first time I got it, I've been meaning to post about it for quite some time now so seeing as I got it again today I took the hint.

The error is horrifingly obvious when you know about it, in short, you've no doubt got some code that looks like this:

String.Format("<html><head><styletype=\\"text/css\\">body{color: #fff;}</style><body>...");

Can you spot it now? Notice your style declaration is using the curly brackets? Basically String.Format is interpreting that as a placeholder i.e. {0} and is throwing a wobbly.

The solution is simple too, just replace all opening/closing brackets with two i.e:

String.Format("<html><head><styletype=\\"text/css\\">body{{color: #fff;}}</style><body>...");

I hope that helps someone out there :)

P.S. Watch out for methods that use String.Format as they may catch you out in the same way -i.e. Subject of System.Net.Mail.MailMessage