Feed Subscribe
Exception has been thrown by the target of an invocation.

N2CMS, NHibernate, SqlCommandSet and medium trust

by ondrejsv 15. May 2011 13:14

Recently I installed the current version of the N2CMS to power my personal homepage. I’m running on shared webhosting so you may imagine how poor performance is. To speed up the thing a little I decided to switch from SqlCe database to the full blown SQL Server.

However, after changing the connection string the N2CMS does not even install itself:

Attempt by method 'NHibernate.AdoNet.SqlClientSqlCommandSet..ctor()' to access method 'System.Data.SqlClient.SqlCommandSet..ctor()' failed.

If you carefully look at the source code of the NHibernate.AdoNet.SqlClientSqlCommandSet, you will discover the ugly reflection:

/// /// Expose the batch functionality in ADO.Net 2.0 /// Microsoft in its wisdom decided to make my life hard and mark it internal. /// Through the use of Reflection and some delegates magic, I opened up the functionality. /// /// Observable performance benefits are 50%+ when used, so it is really worth it. /// public class SqlClientSqlCommandSet ...
static SqlClientSqlCommandSet() { Assembly sysData = Assembly.Load("System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"); sqlCmdSetType = sysData.GetType("System.Data.SqlClient.SqlCommandSet"); Debug.Assert(sqlCmdSetType != null, "Could not find SqlCommandSet!"); }

To continue installing, either make the reflection work by switching your application to full trust (provided your hosting company will allow this):

or disable NHibernate batching feature (and you will lose “observable performance benefirst 50%+” as the author of the NHibernate comment claims Smile) by following the commit message:

Enabling batching is done by defining (the new) property "hibernate.batch_size" to a size greater than zero. This way require an explicit action to enable it, but this is probably a good thing.

Tags: , ,

Visual Studio 2010 SP1 reapplication fails

by ondrejsv 6. May 2011 18:16

My first attempt to install VS 2010 SP1 failed as the setup hanged (see Visual Studio 2010 Service Pack 1 installing for over 2 hours could be a sign of a problem). The real problem was the rollback also hanged and this is always a sign of big trouble.

After reboot I started SP1 setup again and chose to reapply SP1. In a while I was prompted to find silverlight_sdk.msi because the installer could not have found it. It is located in the Silverligh4/1033 folder on the installation media. The installer seemed to be happy with my choice and continued. Almost at the end of the installation I was prompted again – now for the vc_runtime_x86.msi  - twice and then again twice for vc_runtime_x64.msi. However, the message at the end of the installation was not what I wanted to see: Reapplication did not succeed. The very same a few times I tried it again and again.

VS 2010 SP1 log reads:

Final Result: Installation failed with error code: (0x80070643), "Fatal error during installation. " (Elapsed time: 0 00:33:06).

The big SP1 log contains links to logs of all setup it runs, including setup for Silverlight 4 SDK and VC++ runtimes.

The log for Silverlight 4 SDK:

MSI (c) (DC:98) [16:40:02:132]: SOURCEMGMT: Trying source E:\Silverlight4\1033.
MSI (c) (DC:98) [16:40:02:231]: Cloaking enabled.
MSI (c) (DC:98) [16:40:02:232]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (DC:98) [16:40:02:232]: Connected to service.
MSI (c) (DC:14) [16:40:02:253]: SOURCEMGMT: Resolved source to: 'E:\Silverlight4\1033\'
MSI (s) (EC:10) [16:40:02:259]: Product: Microsoft Silverlight 4 SDK -- Error 1706.No valid source could be found for product Microsoft Silverlight 4 SDK.  The Windows Installer cannot continue.

Error 1706.No valid source could be found for product Microsoft Silverlight 4 SDK.  The Windows Installer cannot continue.

The solution is to manually uninstall Silverlight 4 SDK and Visual C++ runtimes (both 32- and 64-bit flavors) from the Programs and Features Control Panel applet (aka Add Remove Programs).

And then Smile



Windows Live Writer crashes on start when My Documents folder is not accessible

by ondrejsv 26. December 2010 12:13

Today I couldn’t start my Windows Live Writer as it had been constantly crashing on start. I had the 2010 version and the error exception on start was the infamous NullReferenceException. I upgraded to the latest Writer 2011 but no lack – this time it kept crashing with Windows Live own exception DirectoryException (obviously the team in the 2011 version did some more checks and create a special exception). But why?

It choked in the WindowsLive.Writer.CoreServices.ApplicationEnvironment method. A little dig in the WindowsLive.Writer.CoreServices.dll in the Reflector shows the culprit:

path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); _myWeblogPostsFolder = _userSettingsRoot.GetString("PostsDirectory", null); if (string.IsNullOrEmpty(_myWeblogPostsFolder)) { if ((_productName == "Windows Live Writer") && string.IsNullOrEmpty(path)) { throw new DirectoryException(MessageId.PersonalDirectoryFail); } _myWeblogPostsFolder = Path.Combine(path, "My Weblog Posts"); }

Indeed, the Environment.GetFolderPath(Environment.SpecialFolder.Personal) gave null result since I don’t have a custom path for saving blog posts set in the Windows Live Writer.

Then I remembered that we have the My Documents folder redirected on the network share which was unavailable and I had turned off the offline files Windows feature (because it slows down the boot time considerably – to 15 minutes and more).

So either connected to the network to have your My Documents folder accessible or make it available offline when using Windows Live Writer.


It’s time to throw away greedy Firefox

by ondrejsv 28. August 2010 14:47

A quick quiz for today. What application that ate 1,3 GB of my memory and 50 % CPU I forcefully ended in the Task Manager to give me such a picture?:


Yes, Mozilla Firefox. What I dared to do? Download 3 files 300 MB each in size. Apparently Firefox Download Manager holds them in the memory until it downloads them and only then flushes them to disk! Complete fail. I had to switch to the Internet Explorer 8 to download them all (without any problem).

(Yes, I know about 3rd party download managers, I use one of them, but not for such small files.)


VS2010 Bug: Entity Data Model Wizard disappears after selecting “Generate from Database”

by ondrejsv 6. June 2010 17:55

Today I found another annoying bug in Visual Studio 2010. I often work connected to my company LAN via VPN and I have generated some entity data models from databases over the wire in the past. Entity Data Model Wizard which runs when you add a new “ADO.NET Entity Data Model” item in Visual Studio has a “nice feature” that it remembers all connections you entered into it. Of course, if you disconnect from LAN, those connections are not available. If you are unlucky enough, one of those connections may be the first one and default in the combobox where you can select an existing connection to base your EDMX on. Visual Studio probably tries to get information on tables or whatever from the database but if the database is not reachable, it fails very silently and closes the window instead of letting you to select another connection or create a new one. #fail

Fortunately, these connections are the same you see in the Data Connections node of the Server Explorer. So delete all of those which are remote and you have no connection to them any more and the Data Model Wizard would behave properly.