2

Please, help me to understand one thing in Sharepoint, as I'm very new in it...

I have an SP site with many related lists. There are different custom forms (NewForm, for example) that have code behind, as I understand it was designed in Visual Studio 2010, then packed to .dll, signed by .snk/.pfx and stored to GAC. Or maybe it was deployed using .wsp package. In .aspx page I can find an assembly that points to my .dll:

... Assembly=MyCorp.AssemblyName.SomeSpace, MyCorp.AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8e961163eb5c9cc ...

Now, if I try to sign .dll with another .snk/.pfx and put it to GAC I'll get another public key. I'm changing PublicKeyToken in the .aspx page, restarting IIS and then getting a error. Then I look for corellation ID in logs and find something like "NullReferenceException". The thing I can't understand - the code was not modified, just the PublicKeyToken... Why this doesn't work? Or I'm just simplifying, and everything is much more complicated?

Thanks in advance!

P.S.: Sorry me for my bad english, it's not native for me.

  • A NullReferenceException sounds like an error in the code. If the public key token was wrong I'm pretty sure you'd get a "Could not load file or assembly" or something to that affect... – RJ Cuthbertson Feb 26 '14 at 15:12
  • Ok, I found one webpart (from this .dll) with error "The type could not be found or it is not registered as safe". I tried to add 'safecontrol' to web.config, but the problem is that webpart refer to old assembly key. I also tried to change assembly in WebPartNameUserControl.ascx file... Doesn't work. =( – Alex Feb 26 '14 at 15:30
1

When you deploy a web part in SharePoint, you provide it a type and assembly in an xml file that registers the web part in SharePoint.

Look at this: Web Part Deployment

In the .webpart file you'll see the line

<type name="ExecutionModels.Sandboxed.AggregateView.AggregateView, $SharePoint.Project.AssemblyFullName$" />

If you're rebuilding the assembly, it now has a different key here.

In order to update this reference, you'd need to either rebuild the source project including your changes, or update/overwrite this file in the web part gallery. You can do that with a module and the .webpart file without including the user control if need be, as the .ascx already exists in the CONTROLTEMPLATES directory.

But maybe you should stop and think for a second about how you're going to maintain this solution going forward, and what impact this will have on your disaster recovery plan. If anything ever happened to your server would you want to have to be making these same hacky changes again?

  • Unfortunately, now the only thing is important is that "it should be done yesterday", so I'll think about recovery plan a little bit later. But thanks anyway! – Alex Mar 6 '14 at 16:35
-1

from my basic understanding a private key would be used when you have a webpart that its dll will be within the GAC (assembly folder) as they need to be strongly named to be within that folder!

The fact that you have rebuilt the project and added it back into the gac means your key is fine as you wouldnt of been able to add it as the wsp would of failed uppon deployment.

the real question is why are you changing the public key token that is registered to the dll from the aspx file, this should only be done in visual studios? the key is used as another layer of security as its in a core windows folder that has extra security encapsulating the folder. If you change the key from the aspx than the dll would have a missmatch? you get me? to change the key you need to rebuild the project dll and add it back into the assembly folder!

in your case the dll has a fixed key that is stored within the assembly folder that is tied to the dll, when your app (webpart, aspx, feature ect) wants to use the dll it has a different key leading to NullReferenceException as its a missmatch! you need to change the key properly.

that is if i got you right?

to change the key if that is your issue you need to:

goto your visual studio project -> click on project in the top menu -> goto the bottom of the menu and click on properties -> wait for tab to load and then click on signing on the left hand side -> make "sure sign the assmebly" is checked -> click the drop down box and click on "" -> wait for the popup and enter the name "Key" and a password below, re-enter the password in the last box and click ok -> rebuild project -> goto wsp and redeploy -> you should now see the key has changed properly within assembly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.