Click here to monitor SSC

Damon Armstrong

Caffeine Induced Tirades about .NET and Life
And don't forget to check out my latest Simple-Talk articles
View Damon Armstrong's profile on LinkedIn      Add to Technorati Favorites      Add to Google     

VSeWSS 1.3 - Getting around the "Unable to load one or more of the requested types" Error

Published Monday, September 14, 2009 1:35 PM

I hate packaging SharePoint solutions by hand.  Once you've got it working, it's not a big deal, but it takes a lot of reading and remembering each time you start one anew.  VSeWSS is a nice tool that integrates with Visual Studio 2008 and builds out SharePoint solution files auto-magically.  However, it has its quirks.  Quirks that irk me to no end because it feels like it's a constant struggle to get it to do what you want. 

I've got a templated web part base class that I use on a lot of SharePoint projects because it really helps separate out the UI from the business logic.  In the past, we've just copied the code from project to project.  In an attempt to avoid code strewn about all over the place, I decided to pull it back into a single assembly where it could be maintained more easily.  So, after a bunch of work, I went to package things up with VSeWSS and I received the following error:

VSeWSS Service Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Wonderful.  A bit of digging revealed that this is an issue if you're web parts reference a base class in another assembly.  For real?  Seems like that's a pretty big issue since copying and pasting code from project to project is frowned upon in terms of maintainability. 

Then I used all of my mental devices and .NET knowledge to create a plan so cunning that it would circumnavigate the issue entirely.  Make an dummy class in the project that inherits from my base class in the assembly.  As such, the base class would be in the project itself where VSeWSS could see it, but the REAL code would be in the external assembly.  Shear genius!

Yeah, that didn't work.  Apparently you can't have a base class ANYWHERE in the inheritance chain.  That left me with a big WTF moment.  I was seriously miffed that this would not work.  If you look into the error that VSeWSS throws, you'll see it's a reflection error.  So I hashed together my next, slightly less cunning, plan:  throw copies of my assembly everywhere and anywhere that VSeWSS could be looking in the hopes it would magically find it.  I ran the VSeWSS packager, and it packaged everything up without error.  So then it was a process of elimination as I removed the assembly from the various places I had placed it.  In the end, I found that in order for VSeWSS 1.3 to see your external base class, you need to copy your assembly to the following location:

C:\Program Files\Microsoft SharePoint Developer Tools 9.0\svc\bin

This appears to have worked for my scenario, though I'm not sure if such is always the case.  I was also really surprised that putting the assembly in the GAC seemed to have no effect. 

by Damon

Comments

 

Krister A Klaussen said:

Very good post, i laughed so hard i cried. Came across a script for copying the dlls to VSeWSS bin folder on post build, but cant seem to get it to work. Maybe someone else can get some use from it. So here it is:
http://blogs.msdn.com/erwinvandervalk/archive/2009/04/10/program-to-interface-in-sharepoint.aspx

Regards
Krister
February 12, 2010 2:54 AM
 

Dathan said:

You might also want to check the properties on any additional libraries you are referencing. This issue can occur in the following situation: you add a reference to a 3rd-party or other external .dll before you add it to the GAC (for example your templated part), in which case Visual Studio may set the “Copy Local” property to true. In this situation, if the .dll is also already deployed to SharePoint via the GAC or directly, VSeWSS may begin to intermittently raise this error because (I believe) it then tries to also de-and-re the 3rd party lib in the GAC.

Punch line: make sure Copy Local is set to false for any libraries that are not specifically part of your project development.

Note that this can also happen if you upgrade for example from System.Web.Extensions 1.x to 3.5 where you may be changing versions of related .dll references in your project. This is when we see it crop up most often — for example updating to 3.5 version of a dependent lib after updating MOSS 2007, where you may drop the 2.x .dll from the GAC to be replaced with the 3.5 version and update your project references at the same time not noticing the Copy Local property.
February 20, 2010 9:29 AM
You need to sign in to comment on this blog
<September 2009>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. Wesley David... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across and started getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...