升级VS至17.5.2后Kentico Xperience 13站点启动异常求助
使用Kentico Xperience 13开发的基于.NET 6的网站已稳定运行一年以上,将Visual Studio升级至17.5.2(同时安装了.NET 7组件)后,重新构建生产站点,无论是IIS还是IIS Express均无法启动。Visual Studio无编译报错,但浏览器抛出以下异常:
NullReferenceException: Object reference not set to an instance of an object.
CMS.Membership.Internal.VirtualContextAuthenticationConfiguration.get_Audience()DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor()' on type 'VirtualContextRequestPrincipalRetriever'.
Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()DependencyResolutionException: An exception was thrown while activating λ:Kentico.Web.Mvc.Internal.IRequestPrincipalRetriever[] -> Kentico.Content.Web.Mvc.VirtualContextRequestPrincipalRetriever.
Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Actionnext)
已尝试卸载.NET 7、重新安装Visual Studio,问题仍未解决。
- 校验Kentico包版本兼容性:确认所有Kentico相关NuGet包(如
Kentico.Content.Web.Mvc、Kentico.Web.Mvc等)的版本与Kentico Xperience 13官方兼容版本一致,避免VS升级后依赖包意外更新导致的注入错误。 - 锁定.NET SDK版本:在项目根目录创建
global.json文件,强制指定使用.NET 6 SDK构建,防止VS默认调用.NET 7 SDK:{ "sdk": { "version": "6.0.408", "rollForward": "latestMinor" } } - 清理项目缓存与依赖:
- 删除项目目录下的
bin和obj文件夹 - 在Visual Studio的「工具」→「NuGet包管理器」→「包管理器设置」中,点击「清除所有NuGet缓存」
- 重新还原NuGet包并重新构建项目
- 删除项目目录下的
- 检查认证配置项:异常指向
VirtualContextAuthenticationConfiguration.Audience为空,确认appsettings.json或Kentico配置中已正确设置虚拟上下文模式下的Audience参数,确保配置项存在且不为空。 - 安装Kentico最新补丁:登录Kentico官方门户,下载并安装对应版本的累积更新,修复VS 2022升级后的兼容性问题。
内容的提问来源于stack exchange,提问作者Sylvain C.

