My code generate some dynamic HTML fragments and I want to know does the html valid. Thanks to HtmlAgilityPack it is easy: Debug.Assert(IsValidHtmlFra... public static bool IsValidHtmlFragment(string html) { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocumen... doc.LoadHtml(html); return (doc.ParseErrors.Count==0); } ......
We have the following code, ImageButton btn = buttonLookupTable[buttonName] as ImageButton; if (btn != null) { btn.ImageUrl = sUrl; } It is almost always works fine, but sometimes we've got the error: System.ArgumentException: An entry with the same key already exists. Stack Trace : at System.Collections.Speciali... key, Object value) at System.Collections.Speciali... key, Object value) at System.Web.UI.StateBag.Add(... key, Object value) at ......
My application uses a lot of AppSettings to enable/disable different function and I wanted to created unit tests for different combination. I found the simplest way is to create static class data field, that is set to null by default, and loaded from config file if it is null. This allows in unit test methods to explicitely assign values, and when you want return to reading from config file, just reset it to null. static private bool? st_bAPIEnabled; public static bool IsAPIEnabled() { st_bAPIDomesticEnabled ......
I have quite complicated class and I wanted during debugging/testing to validate that the data in the class is consistent. So I created a method Validate and used it in unit testing class MyComplexClass oClass= MyComplexClass.CreateClass(); Assert.IsTrue(Validate(oCla... But then I understood, that it would be better to call this function in the code to ensure that validation happens in the application, not only in unit testing. So I've added Validate method to the end of my CreateClass() method ......
In my recent post ASP.NET Exception Handling links I wondered why in the article Rich Custom Error Handling with ASP.NET Session is not considered to pass Exception details between global.asax: Application_Error and Rich Custom Error Pages with Redirect method. The article compare different state possibilities : Application, Context, Cookies, and QueryString. The application that I am working with used Cache(which technically works as the same way as Application) with SessionID as a key and Response.Redirect() ......
I've had a code similar to the following: string sSql = String.Format("Column1 LIKE '%{0}%'", StringValue); fareRows = dataset.Table.Select(sSql); And DataTable.Select method returned me "Cannot perform 'Like' operation on System.Int64 and System.String". System.Data.EvaluateException: Cannot perform 'Like' operation on System.Int64 and System.String. at System.Data.BinaryNode.SetT... op, Type left, Type right) at System.Data.LikeNode.Eval(D... row, DataRowVersion version) at ......