Tip: Locating the PublicKeyToken of your assembly

Today I ran into a problem concerning a custom webpart. The webpart compiled, so I shipped it ;). But the designtime/compile success was not a guarantee for runtime success. I ran into the following error: Could not load file or assembly ‘xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx’ or one of its dependencies. The system cannot find the file specified.

So what does this mean? For me the problem was that my libraries were re-signed and in my code there was something like this: <%@ register=”” tagprefix=”CustomControls” namespace=”xxx” assembly=”SharePointControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789″> While in the GAC the assembly had another PublicKeyToken.

When resigning your assemblies, the public key tokens change and an assembly (dll) with the same name is seen as a different version. Which is quite logical because that is what signing with a strong name is meant for.

Next problem is how to get the strong name of my newly signed Assembly, so we can change it in our code. A solution is to deploy your assembly in the GAC and look the PublicKeyToken up in the Assembly folder. There is another solution which is more permament colleague of mine showed it to me:

In Visual Studio, click “Tools” -> “External Tools”. This will open a window in which you can add the command SN as a tool. In the window click “Add” and fill in the fields as seen in the image below. Don’t forget to check the “Use Output window” check box.

PublicKeyToken Tool

PublicKeyToken Tool

When done you can use the tool by selecting the assembly of which you want the PublicKeyToken and clicking the tool  in Visual Studios “Tools” menu. The PublicKeyToken will be displayed in the output window.

That’s all for now folks, happy SharePointing.

Error: The type or namespace name ‘xxx’ could not be found

Today I ran into a small programming related issue. As I was working on a webpart, I was trying to use an UpdatePanel control. So I referenced the System.Web and added the using statements:

  • using System.Web;
  • using System.Web.UI;

But still got me the nasty The type or namespace name ‘UpdatePanel’ could not be found (are you missing a using directive or an assembly reference?) 

Well of course not I added all the needed directives and assemblies. Or didn’t I?

UpdatePanel is an extension, it used to be in the Atlas library which later became Ajax.NET so don’t forget to also reference System.Web.Extensions. This should solve your problems. As it is plain .NET code it is something that works in SharePoint as well as other .NET applications.

Can be a tricky little thing, and of course it doesn’t only go for the update panel but for all the Ajax controls.

So that’s it for now, hope to see you soon, untill then happy SharePointing.