This is a place to record my journey with SharePoint. I realized that I was learning a lot of stuff that other people would probably like to know about (and that I would like to refer back to... I'm getting kinda old and my memory is fading.)

Sunday, April 13, 2008

Missing Method Exception (or why my Unit Tests would not work with my SharePoint project)

I'm using some test driven development concepts on a little SharePoint development project.

I noticed that I kept running into a really strange error every time I added a new Method to my SharePoint project.

Whenever I would run my new Unit Test I would get a System.MissingMethodException error saying that the method in my SharePoint project could not be found.

Turns out that the problem was caused by the fact that the Unit Test project was loading my SharePoint assembly from the GAC.  So for me to get the tests to work I had to install the latest version of my SharePoint assembly into the GAC and then close/open Visual Studio.

I like to take very small steps when I develop (add some functionality, test it, add some functionality, test it).  So the idea of constantly updating the GAC and closing Visual Studio was not appealing.

I considered removing my SharePoint assembly from the GAC, but I put it in there for some legitimate reasons.

After much trial and error I found a solution that works okay (but is not ideal).  I configured my Unit Test project to install the SharePoint dll in the GAC whenever the project is compiled.  And I run the Unit Tests in Debug mode.  With this setup I am able to get instant feedback from my changes.

As I said it is not ideal, but works.

To install my SharePoint dll in the GAC I added a Post Build event to my Unit Test project.  It just runs the gacutil command.

To run my Unit Tests in debug mode I launch my tests using the Visual Studio Debug option rather than Run option.

VSNET_UnitTest_SnapShot

I am using Visual Studio 2008 Test project for my Unit Tests.

0 comments:

Subscribe to my Blog

Blog Archive

About Me

My Photo
Jeff Dalton
I have been in IT for the past 16 years working with many different technologies and in many different roles. Today my main focus is on moving a CMS 2002 / SharePoint 2003 solution to SharePoint 2007.
View my complete profile