I am getting "object reference error" while putting string.format in stringbuilder. I have below code in C#2.0
public const string PageLinkGoogleMarkup = "<link rel=\"alternate\" hreflang=\"{0}\" href=\"{1}www.mysite.com{2}{3}\" />\r\n";
Now when I am adding this to HtmlTextWriter it is working fine, as below:
HtmlTextWriter writer (Object);
writer.write(string.format(PageLinkGoogleMarkup,str[1],header,links,querystr)); //This works perfect
And when I tries to add this above code to StringBuilder instead of HtmlTextWriter it gives error:
As there is big loop so I decided to go with appending everything to StringBuilder first and at last rendering using writer.Write (Whole html in a bunch), please below code
StringBuilder sb = new StringBuilder();
sb.Append(string.format(PageLinkGoogleMarkup,str[1],header,links,querystr)); //here i get object reference error
writer.Write(sb.ToString());
Please suggest!!
Thanks.