Sunday, June 3, 2012

DatabaseFactory.CreateDatabase error- Object synchronization method was called from an unsynchronized block of code.

Yesterday one of my friends called me and said that he was getting an unusual exception form one of the projects which I had created long back. The only change he made was to add the latest Microsoft.Practices.EnterpriseLibrary  library 5.0.414.0

The error was 
 Object synchronization method was called from an unsynchronized block of code.

The error observed was at the following line

Database db = DatabaseFactory.CreateDatabase(_conStringName);

This was a code which was runninig successfully foer years. Initially I suepected trhat my firend had accidentyly made some mistake but when I reviewed the code I didn’t see much changes. I quickly made the following changes in the code & it worked !!!
SqlDatabase db = new SqlDatabase(_conStringName);

I think Microsoft should be more careful in making such changes which affect the existing runninig code. 

No comments:

Post a Comment