views:

175

answers:

2

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?

A: 

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.

Steve Danner
Thanks so much for this info, I no nothing of this, so this will get me going. In the hopes you can answer some follow up questions easily, i'll ask a few more questions...(I did verify the "Signing" tab thing. Question 1...is C:\Windows\assembly the GAC? 2. When you say drag and drop from "bin", where is this "bin" dir?
bmw0128
Yes, C:\windows\assembly is the GAC. When you open it in explorer, it should look different than a normal folder. The bin directory is a subdirectory of your visual studio project folder where the output dll goes on a build.
Steve Danner
thanks again...i noticed that the dll is placed in my VS project folder in a sub-dir called "debug", i'm assuming that is ok. So if my dll is not getting to GAC using gacutil.exe, i'll assume i am not doing the signing thing correctly?
bmw0128
That is fine for your debugging purposes, but you'll want to compile a release build before you deploy to your production environment. It sounds more like gacutil isn't being called correctly as you verifyed the info I talked about in the "Signing" tab.
Steve Danner
+2  A: 

"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

Logan Capaldo
I need to look up sn.exe, its new to me...
bmw0128

related questions