You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 9 MAUI项目中Prism.Maui类型未识别(含CS0234等错误)

问题描述

原本基于.NET 8的MAUI项目,因MAUI工作负载问题升级至.NET 9(预览版),安装了最新版Prism.Maui相关包,.csproj中已添加:

<PackageReference Include="Prism.DryIoc.Maui" Version="9.0.537" />
<PackageReference Include="Prism.Maui" Version="9.0.537" />

代码中引用了命名空间:

using Prism.DryIoc;
using Prism.Ioc;

但仍出现以下编译错误:

Error CS0234: The type or namespace name 'DryIoc' does not exist in the namespace 'Prism' (are you missing an assembly reference?)
Error: The type or namespace name 'PrismApplication' could not be found
Error: The type or namespace name 'IPlatformInitializer' could not be found

项目目标框架为net9.0;net9.0-ios,NuGet包已安装并显示在.csproj中,已执行清理、重建,重启解决方案和Visual Studio 2022预览版(已安装.NET 9工作负载)。

解决方案
  • 适配Prism API变更
    Prism.Maui针对.NET 9做了API调整:

    • 不再使用PrismApplication,改为通过PrismAppBuilder初始化项目:
      var builder = PrismAppBuilder.CreateBuilder(args)
                                  .UsePrism(prism =>
                                  {
                                      prism.RegisterTypes(container =>
                                      {
                                          // 注册服务逻辑
                                      });
                                  });
      
    • IPlatformInitializer已被移除,平台初始化逻辑需移至MauiProgram.cs的ConfigureLifecycleEvents或直接在平台项目中处理;
    • Prism.DryIoc命名空间可能已调整,尝试直接引用DryIoc命名空间,或确认Prism.DryIoc.Maui包是否自动引入了DryIoc依赖。
  • 调整NuGet包版本与安装方式
    卸载所有Prism相关包,执行命令dotnet nuget locals all --clear清理NuGet缓存,仅重新安装Prism.DryIoc.Maui包(该包已包含Prism.Maui依赖,无需单独安装)。若当前版本存在兼容性问题,可尝试降级到Prism的稳定版本(如9.0.401)或升级到最新预览版。

  • 验证项目与环境配置
    检查.csproj的目标框架配置是否正确,确保无多余框架引用:

    <TargetFrameworks>net9.0;net9.0-ios</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
    

    打开Visual Studio安装器,确认.NET 9预览版的MAUI工作负载已完整安装;同时将Visual Studio 2022预览版升级到最新版本,保证与.NET 9的兼容性。

内容的提问来源于stack exchange,提问作者Ismail Sirsikar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 21:23:12