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

Visual Studio and Resharper snippet for MSTest method

by ondrejsv 18. May 2011 22:28

Visual Studio comes with an OOTB MSTest method snippet accessible via the testm shortcut. Two thing missing in it for me:

  1. standard naming convention as mentioned also in the The Art of Unit Testing by Roy Oshrove (TestedMethod_StateUnderTest_ExpectedResult),
  2. separation of Arrange, Act and Assert parts of the code by clearly visible comments.

I’ve been observing that VS code snippets are for not widely used some reason. Perhaps the clunky Snippet Manager in Visual Studio or necessity to edit snippets in XML by hand… who knows…

So here’s how looks my new snippet:


Trivial as it is but useful very much.

Download clean VS version or ReSharper snippet (aka Live Template).


Fighting the spam II

by ondrejsv 15. May 2011 19:51

I was running on BlogEngine 1.5 with Askimet antispam protection until today. BlogEngine became notoriously infamous for allowing spammers post fake comments. Just make an image yourself:


More than 8500 comments waiting for approval and 225 automatically approved comments – among these approved comments majority is successful spam that got through antispam filter.

It is above human forces to go through all these thousands of comments so I ‘m going to write a script against BlogEngine API to delete it all – sorry if any of your comment is there.

I upgraded to BlogEngine 2.0 and enabled TypePadFilter together with Askimet. Also I enabled SimpleCaptcha which asks you a simple equation before it allows to post your comment. And I was forced to automatically close posting new comments after 90 days just for sure. Sorry for any inconvenience. If you want to write me about an article posted 90 days ago you may do so by using the contact form directly.

UPDATE: Clearing unapproved comments was not difficult at all – BlogEngine has even a built-in method for that in its web services API  -- it’s well hidden in the api/Comments.asmx service and it’s name is DeleteAll (don’t get confused by its name; it deletes only unapproved comments as you can see from source codes).



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