Update broken package reference

Don Rea asked on June 9, 2022 21:38

We have a Kentico 11-based web site. There are development copies of the site that include all custom source code, and the production and testing sites include only the CMS files and the .dlls in the bin directory. When we add or modify a class defined in one of those assemblies we build the .dll in a development environment and copy it to the bin directory of the deployment environment. This process has served us well so far.

Recently we decided to send all email from the site through SendGrid, as our existing email process is becoming unusuable. We added the SendGrid NuGet package to one of our custom projects, created a provider class overriding the CMS built-in email provider for using the SendGrid methods, and built and tested. It worked great in the development environment.

When we deployed the .dll to the testing environment that site began failing to load with an application error. A look in the event viewer turned up this:

Exception information: 
    Exception type: HttpUnhandledException 
    Exception message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.cmsmessages_error_aspx.ProcessRequest(HttpContext context)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)

Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at CMS.Base.Web.UI.ScriptHelper.NewtonsoftJsonSerializer..ctor()
   at CMS.Base.Web.UI.ScriptHelper.<>c.<.cctor>b__162_0()
   at System.Lazy`1.CreateValue()

Indeed the Newtonsoft.Json library was upgraded on development as part of installing SendGrid, which wanted a newer version. What I don't understand is why this same error did not appear there, and what I don't know is how to correct this in the test and production environments. If this were happening in one of our custom assemblies I could just update the package and rebuild, but since this is one of the CMS assemblies for which I don't have source I really don't know what to do.

How can I update the reference to Newtonsoft.Json for assemblies for which I do not have source? Or is there some better way to correct this?

Recent Answers


Don Rea answered on June 9, 2022 22:33

Editing the main web.config's dependentAssembly entry for Newtonsoft.Json to this:

<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="9.0.0.0" />

seems to have solved the problem, even though the actual updated version is 13.0.1.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.