Geeks With Blogs

Michael Freidgeim's Blog MS .Net Development July 2007 Entries
Function to validate Html Fragment
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); } ......

Posted On Thursday, July 26, 2007 5:52 PM

An error "An entry with the same key already exists" when assigning ImageButton.ImageUrl
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 ......

Posted On Thursday, July 26, 2007 3:15 PM

Reading AppSettings to be Unit Test friendly.
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 ......

Posted On Wednesday, July 25, 2007 9:57 AM

Debug.Assert vs Unit Testing Assert. class
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 ......

Posted On Friday, July 20, 2007 6:01 PM

Passing Exception details in Session to Custom Error page.
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() ......

Posted On Friday, July 20, 2007 12:22 AM

Error: "Cannot perform 'Like' operation on System.Int64 and System.String"
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 ......

Posted On Sunday, July 15, 2007 11:39 AM

Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net | Join free