The problem is, when you’re in visual studio debugging a feature receiver, and you have your build actions set to ‘Default’ (ie, not No-Activation), it will deploy the solution, then try and activate your feature (which has your event receiver in it (which probably deploys an SPTimerJob or something similar)). You get the error saying that it cant find your assembly. BS! It’s in the GAC! I can see it, and it’s the right version??
I’ve just been banging my head against the brick wall with this one.
I came across the following article.
But unfortunately it didn’t help me out, the comment someone left in there about using -force was interesting, but I need this to work within VS… if I just use powershell, it activates fine.
The quick and (maybe a little bit dirty) solution for me (without needing to create and move a bucket load of code into a new project), is simple: Bump the version number on the assembly that contains your event receiver (read: the assembly you’re deploying to the GAC). Go into the assemblyInfo manifest, and update the version from 1.0.0.0 to 1.0.0.1, then redeploy. Violla… the problem will go away (or at least, it did for me).
Second to this, you’ll notice then that all references to the Strong Name of that assembly then need to be updated. If you’re referencing it in user controls and so forth, take a look at replacing the Version= component of the strong name with: Version=$SharePoint.Project.AssemblyVersion$
The sharepoint project system in VS will replace this macro with the current assembly version, saving you having to update it each time when you change it (when you get this error, for instance
).
All web part pages will need to be updated as well, (ie web parts need to be reimported, because the version changed). Do it once, and you shouldn’t see it again (not sure what originally caused it… but for me, it was after a reboot! Random.).
Enjoy!
UPDATE:
Earlier this week I found myself delving deep into the realms of timer jobs, and found that the SharePoint Timer Service loves to cache assemblies (Objects table in sp config). I received this same error today. Using my knew found knowledge as a premise, I retracted my solution in VS, I then restarted the SPTimerV4 service, then redeployed the solution – the features now activate. I think the reason it can’t find the assembly is something to do with it using an older cached version of the assembly, and because (correct me if I’m wrong) that feature activation is run through the timer service, this some how relates to it not being able to find the assembly.
[...] Feature could not be installed because the loading of event receiver assembly X failed: [...]