In SharePoint 2007, upgrading a Web Part to a new version number was a bit complicated. But as Maurice Prather nicely explains in this article, this has become much simpler in SharePoint 2010. Although, due to a small bug, again described by Maurice in another great article, taking advantage of this in existing projects requires a bit of luck. If your public key token contains one or more byte pairs with a leading 0, you are not so lucky. As Maurice explains, the 0 will be stripped from the PublicKeyToken attribute of the BindingRedirect element in web.config. This will of course cause the binding redirect to fail, and the Web Part will render an error message.

I was a bit surprised to see that this was not fixed in SP1, but luckily we didn’t have to wait that much longer. I have just tested this after installing the June CU and now it works as it should! I followed these steps:

  1. Create an empty SharePoint project.
  2. Add a strong name key file with a key like this: 0408d0be841e7310.
  3. Add a web part to the default feature.
  4. Deploy the project to a web application in a pre-June CU installation of SharePoint 2010.
  5. Add a web part to a page, and verify that it renders correctly.
  6. Update the assembly version of the project to 2.0.0.0, add a SafeControl entry for version 1.0.0.0, and a BindingRedirect element to the solution manifest.
  7. Deploy the project again, and confirm that the web part fails to render. Verify that the strong name key in web.config is incorrect, like this: 48d0be841e7310.
  8. Update SharePoint to the June CU, and deploy the solution package again. Verify that the web part now works as expected, and that a correct public key token has been added to web.config.