Thursday 30 August 2007

Databind: Object does not match target type

This error sometimes occurs when trying to bind a result from a NHibernate query. It is caused by the first item in the list being a proxy value which causes the DataBind to use reflection of the proxy rather than the real target.

Details and solution taken from Alkampfer's Place.

Possible solution, requires object implements ICloneable:


public IList<T> SafeList<T>(IList<T> input) where T : class, ICloneable {
//Symply check the type of the first element.
if (input.Count > 0) input[0] = (T) input[0].Clone();
return input;
}



If object does not implement IClonable then need to turn off Lazy loading in mapping file.

Final Solution
As it was not pratical to make all objects ICloneable or to turn off lazy loading we finally settled on clearing the cache (Session.Clear) prior to executing queries or criterias.

Wednesday 29 August 2007

LoginStatus - Login page URL

When using LoginStatus control the Login link goes to the page identified in the web.config:


system.web
authentication mode="Forms"
forms loginurl="~/Default.aspx"