Key File, GAC, DLL... Feature could not be installed because the loading of event receiver assembly failed

0

I'm doing my first DLL, a simple HelloWorld SharePoint Feature. The Feature has an event handler, therefore code beside a feature.xml and elements.xml file. I can build the solution fine, and I have a post build script that calls gacutil.exe. Then I added a key file, I chose a random name, and added it the solution. In the feature.xml i have:

ReceiverAssembly="HelloWorld, Version 1.0.0.0, Culture=neutral, PublicKeyToken=b59ad8f489c4a334"
ReceiverClass="HelloWorld.FeatureReceiver"

I made up the value in the PublicKeyToken.

The Feature will not install, I get:

Feature 'b2cb42e2-4f0a-4380-aaba-1ef9cd526f20' could not be installed because the loading of event receiver assembly "HelloWorld, Version 1.0.0.0, Culture=neutral, PublicKeyToken=b59ad8f489c4a334" failed: System.IO.FileLoadException: Could not load file or assembly 'HelloWorld\, Version 1.0.0.0\, Culture\=neutral\, PublicKeyToken\=b59ad8f489c4a334' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) File name: 'HelloWorld\, Version 1.0.0.0\, Culture\=neutral\, PublicKeyToken\=b59ad8f489c4a334' at System.Reflection.AssemblyName.nInit(Assembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Since I have no idea what is going on with the key file/signing thing, I'm thinking I am doing something wrong, like does there need to be some tie between the key file name and the info in the feature.xml file?

sharepoint-2007
asked on Stack Overflow Mar 2, 2010 by bmw0128 • edited Aug 22, 2017 by Cœur

2 Answers

4

"I made up the value in the PublicKeyToken."

You can't make this up. It is actually a function of the key you use to give your assembly a strong name. You can use sn.exe -T to determine the actual public key token of your assembly (if it has one). You can use sn.exe -v to ensure that the assembly is properly signed. If it is not already signed, follow Steve's instructions and use sn.exe -T or similar (it will also show up as a column in c:\windows\assembly once you've installed it) to get the real PublicKeyToken and make sure you use that in the feature.xml

answered on Stack Overflow Mar 3, 2010 by Logan Capaldo
0

Everything looks good from what you've shown. Ensure that:

  • The Assembly really is in the GAC with the version and publickeytoken you specify when you are installing the feature (I assume by means of STSADM.exe)
  • If the assembly is NOT in the GAC, you either haven't properly strong named it with your keyfile, or GACUTIL is just failing on your build for some reason.
  • Ensure that the assembly really is called just "HelloWorld" in the GAC.

Go into project properties, see the "Signing" tab, and ensure the "Sign the Assembly" checkbox is checked, and that it's pointing to your keyfile. You can manually install the dll into the GAC by dragging and dropping the file from the bin directory into C:\windows\assembly.

Hope this sheds a little bit of light on how to get your dll into the GAC.

answered on Stack Overflow Mar 3, 2010 by Steve Danner

User contributions licensed under CC BY-SA 3.0