Tip #194: When automatic update is not your friend

tl;dr

Nuget is a great tool and a real timesaver but beware of automatic updates that can unexpectedly bring incompatible or broken builds of third-party libraries and that will, in turn, break your plugins or workflows.

The real story or “I saw the whole thing”

Friday, August 1st, 6:00PM

All users logoff and CRM is up for a good scrub over the weekend. It’s about to get an upgrade to the latest version of code that has been in development and testing for a few weeks now.

Sunday, August 3rd, 11:29PM

Everything is fine, last full rebuild, deploy, quick check, looks great. CRM is officially online, last sip of cold coffee, go home, crush.

Monday, August 4th, 7:59AM

Your phone rings. “<Insert your name here>! Get your <insert your favorite bodypart here> over here! What’s going on?! <Insert expletive here>! Users cannot update any contacts, they are getting errors?! <Repeat the expletive>”

Your get your sore <insert the above bodypart here> out of bed, drag it to work and the fun begins…

The error users are getting is:
Unexpected exception from plug-in (Execute): Foobar_Plugins.Newton: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

What’s going on?!

It was all working yesterday

Yesterday  is a key word here, as it turns out, a lot of things can happen in a day. The error message indicates that someone wants to call reflection methods. As it turned out, one of the plugins uses Newtonsoft.Json and includes code similar to

using Newtonsoft.Json;
...
public class SuperDuperPlugin : IPlugin
{
...
    var foo = JsonConvert.DeserializeObject<Bar>(baz);

What do you know, the library was updated to version 6.0.4 on precisely 3rd of August and update dragged in reflection into DeserializeObject method. Why did you get this nastiness? Because your build process included magic line

update-package Newtonsoft.Json

which resulted in version 6.0.4 overwriting working build 6.0.3. How to rollback to the working version? In Visual Studio go to TOOLS > NuGet Package Manager > Package Manager Console then run the following command

get-project -all | 
   update-package Newtonsoft.Json -Version 6.0.3

Lesson: automatic updates are nice but beware of incompatibilities and bugs that these updates can bring into your solution.

Share on FacebookTweet about this on TwitterShare on Google+

Leave a Reply

Your email address will not be published. Required fields are marked *