Kentico 12 to 13 Upgrade: 'CMS.Routing.Web.RegisterHttpHandlerAttribute'

Brandon Henricks asked on June 30, 2022 14:50

I have recently run the upgrade tool on a Kentico 12 MVC site, to Kentico 13 MVC.

After installing the new libraries, removing the old libraries, clean and a build.

I am getting the following error:

Server Error in '/' Application. Could not load type 'CMS.Routing.Web.RegisterHttpHandlerAttribute' from assembly 'CMS.Routing.Web, Version=13.0.13.0, Culture=neutral, PublicKeyToken=834b12a258f213f9'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Could not load type 'CMS.Routing.Web.RegisterHttpHandlerAttribute' from assembly 'CMS.Routing.Web, Version=13.0.13.0, Culture=neutral, PublicKeyToken=834b12a258f213f9'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[TypeLoadException: Could not load type 'CMS.Routing.Web.RegisterHttpHandlerAttribute' from assembly 'CMS.Routing.Web, Version=13.0.13.0, Culture=neutral, PublicKeyToken=834b12a258f213f9'.] System.ModuleHandle.ResolveMethod(RuntimeModule module, Int32 methodToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount) +0 System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule module, Int32 methodToken, IntPtr[] typeInstantiationContext, Int32 typeInstCount, IntPtr[] methodInstantiationContext, Int32 methodInstCount) +162 System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +96 System.Reflection.CustomAttributeData..ctor(RuntimeModule scope, CustomAttributeRecord caRecord) +79 System.Reflection.CustomAttributeData.GetCustomAttributes(RuntimeModule module, Int32 tkTarget) +119 System.Reflection.CustomAttributeData.GetCustomAttributesInternal(RuntimeAssembly target) +83 CMS.Core.AssemblyDiscovery.IsAssemblyDiscoverable(Assembly assembly) +19 CMS.Core.AssemblyDiscovery.AddOnlyDiscoverableAssembly(ICollection1 assemblies, Dictionary2 preloadedAssemblies, AssemblyName assemblyName, String filePath) +72 CMS.Core.AssemblyDiscovery.ExecuteGetAssemblies(Boolean onlyDiscoverable) +1168 CMS.Core.AssemblyDiscovery.get_DiscoverableAssemblies() +31 CMS.Core.AssemblyDiscoveryHelper.GetAssemblies(Boolean discoverableOnly) +75 CMS.Core.ModuleDiscovery.GetModules() +99 CMS.Core.ModuleEntryManager.GetDiscoverableModules() +29 CMS.Core.ModuleEntryManager.ModuleCollectionsInitialization() +132 CMS.Core.ModuleEntryManager.PreInit() +21 CMS.Core.AppCore.PreInit() +133 CMS.DataEngine.CMSApplication.PreInit(Boolean initializeContainer) +127 Kentico.Web.Mvc.ApplicationBootstrapper.Run() +130

[InvalidOperationException: The pre-application start initialization method Run on type Kentico.Web.Mvc.ApplicationBootstrapper threw an exception with the following error message: Could not load type 'CMS.Routing.Web.RegisterHttpHandlerAttribute' from assembly 'CMS.Routing.Web, Version=13.0.13.0, Culture=neutral, PublicKeyToken=834b12a258f213f9'..] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +919 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +169 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +172 System.Web.Compilation.BuildManager.ExecutePreAppStart() +172 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +854

[HttpException (0x80004005): The pre-application start initialization method Run on type Kentico.Web.Mvc.ApplicationBootstrapper threw an exception with the following error message: Could not load type 'CMS.Routing.Web.RegisterHttpHandlerAttribute' from assembly 'CMS.Routing.Web, Version=13.0.13.0, Culture=neutral, PublicKeyToken=834b12a258f213f9'..] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111

Any insight here would be helpful

Recent Answers


Liam Goldfinch answered on June 30, 2022 20:45

Is this for the presentation MVC site rather than the admin site?

What the name and version of the new libraries you've installed?

I believe the missing dll is in Kentico.Xperience.Libraries nuget package, have you installed the correct version?

0 votesVote for this answer Mark as a Correct answer

Brandon Henricks answered on July 11, 2022 18:57

Hi Liam,

Thank you for your reply.

I have installed the following libraries on the front end:

Kentico.Xperience.AspNet.Mvc5 Kentico.Xperience.AspNet.Mvc5.Libraries Kentico.Xperience.Libraries

These are all at version 13.0.72

0 votesVote for this answer Mark as a Correct answer

Elmar Höfinghoff answered on November 15, 2022 11:35

I have the same question. Any resolution for this?

0 votesVote for this answer Mark as a Correct answer

Tim Chitty answered on November 18, 2022 13:04

Same here, was this resolved at all?

0 votesVote for this answer Mark as a Correct answer

Alen Genzić answered on December 15, 2022 14:05

I have the same issue. Updated to version 13.0.0 as instructed in the documentation and got the error.

0 votesVote for this answer Mark as a Correct answer

Elmar Höfinghoff answered on December 15, 2022 14:15 (last edited on December 15, 2022 14:18)

Check the web.config if an assembly reference is causing this

0 votesVote for this answer Mark as a Correct answer

Chamara Janaka answered on January 28, 2023 13:24

does anyone have a fix for this? Getting the same error.

0 votesVote for this answer Mark as a Correct answer

Not Applicable answered on January 29, 2023 14:43 (last edited on January 29, 2023 14:44)

Make sure that only your presentation related projects reference the Kentico.Xperience.AspNet.Mvc5 packages. If the CMS project is referencing them as well (also indirectly via other projects), things go wrong with K13.

It's also worth recreating the binding redirects. Open the solution containing all your projects in Visual Studio. I have better results by manually removing all binding redirects first. Search solution-wide for bindingRedirect and remove all dependentAssembly nodes and their child nodes. Then go to the package manager console and run Add-BindingRedirect *. This may take some time, after completion clean and rebuild your solution.

0 votesVote for this answer Mark as a Correct answer

Chamara Janaka answered on January 29, 2023 15:12

@Marcel Vriend I made sure only the presentation project is referrencing the Kentico.Xperience.AspNet.Mvc5 packages and also tried re-adding the binding redirects but no luck.

Thanks

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on January 30, 2023 06:11

What is the 'CMS.Routing.Web.dll' assembly file version in your project? Was it updated? Does the admin app's hotfix version match the hotfix version of the NuGet packages in the front end app?

0 votesVote for this answer Mark as a Correct answer

Elmar Höfinghoff answered on January 30, 2023 09:34

Check the following for a Kentico 13 MVC project:

Kentico Xperience comes with multiple Nuget packags.
Kentico.Xperience.Libraries
Contains all CMS Libs, which can be used by both apps, the CMS and the Presentation WEB App.
Kentico.Xperience.AspNet.Mvc5.Libraries
Contains additional DLLs used in the MVC app. Can be used by ClassLibraries used in the MVC App. Do not use this in the CMS app.
Kentico.Xperience.AspNet.Mvc5
Contains additional Frontend files like Views, Scripts, etc. used in the MVC app. Can be used in the Presentation Web, which has Views and Scripts. You don't have to use this in Class Libraries. Use the Kentico.Xperience.AspNet.Mvc5.Libraries instead. Do not use this in the CMS app.

After upgrading the Nuget packages, check all web.config and/or app.config files in your solution projects for old, not needed DLL references (redirects to concrete DLL versions). Sometimes this is not changed correctly by the Nuget package changing process. If you find any reference here that seems not to be correct, delete the concerned node from the config. Make backups before doing this.
This redirects tell all dependencies where they will find a DLL which is compatible to their referenced version.

Than delete all bin and obj folders and rebuild your solutions.

Other issues could be:
Check all projects in your solution if any of it still uses old DLLs or DLLS which have dependencies to old DLLs.
Check if any project copies old DLLs via XCopy on build into your bin folder. Check if any old DLLs are in your bin folders via source control and are restored.

Another thing you should keep in mind: the CMS app copies all files from the Lib folder into the DLL folder using XCopy command on post build. You can see this in the project properties or the csproj file. This could also be a source of such issues... Check if you have added custom DLLs into the Lib folder.

That are some things I struggled about in the past...

0 votesVote for this answer Mark as a Correct answer

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