Thursday, February 28, 2008
NHibernate flush
Flush(): Unlike its name is suggesting, purpose of Flush() is not to clear cache. It synchronizes the cached objects with the database.In short, you cache and database gets in sync with each other. All that you retrieve using Load(), Get() and List() is entitled to stay in cache. When you do 'save', 'update' or 'delete', operations of NHibernate, not all operations are immediately performed to database. It is when you use 'flush' of NHibernate session, all 'yet to be done' change of database are done. Note that 'flush' is transaction safe. Means, all the operation done in a transaction by 'flush' can be rolled back with other things of transaction.
When to use flush? When you are interested in dirty reading of data, Flush() refreshes your modified data into database (and obviously, does “undo” if the Nhibernate transaction is rolled back) .
What to do to clear cache? Use “Evict” to clear individual object or collection of objects, Isession.Clear() removes all objects.
Wednesday, February 13, 2008
.NET Assembly uninstall problem
Have you ever encountered this error when you try to uninstall a .NET assembly?
Unable to uninstall: assembly is required by one or more applications Pending references:
Most probably yes!
Cause:
It is because that assembly is installed by an installer (anyone.. including standard .net MSI) . Installer specifies a traced reference count on the assembly being installed so when you try to delete assembly using GACUTIL, you get above error. I couldn’t uninstall some assembly while I was manually uninstalling a software.
Work Around:Method 1:
Use GACBrowser software to remove such assembly (uses 3rd approach specified below). It’s Easy, search and select assembly to remove. And removed!!
Download from here: http://sourceforge.net/project/showfiles.php?group_id=214315
GAC Browser is powerful tool to search and remove assembly. It is must have tool for any developer dealing with assemblies. On an average, if you have visual studio 2005 installed on your PC, you may see more than 1000 assemblies on you PC. There is no good way of searching assembly in you GAC unless you have GAC Browser with you. Also visibility in GAC is increased with more info like when it was last GACed. Double click any assembly to de-assemble the assembly in ILDASM. All in one! That’s why I said it a “must have”!
Method 2:
Windows maintains trace reference count in registry at two places.
[HKCU\Software\Microsoft\Installer\Assemblies\Global]
[HKLM\SOFTWARE\Classes\Installer\Assemblies\Global]
So you may want to go to this registry and remove the entry of the assembly that you want to uninstall. Use GACUTIL to remove assembly from GAC.
Method 3:
Go to Assembly folder using command prompt.
1. Open CMD
2. Go to assembly directory (for most of us: C:\Windows\assembly), If you type ‘DIR’, you may find different folders (important are: GAC, GAC_MSIL, GAC_32)
3. Search your assembly folder from this folder, go to appropriate version folder and remove the folder.
Conclusion:
You may want to have GAC Browser software as well has use method 2 for clean operation. GAC browser is soon coming up with in build method 2.