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: , ,