部署MAUI应用至iPhone真机时遇DevExpress原生实例创建错误
MAUI应用部署到iPhone真机时DevExpress原生类加载失败的解决方法
我正尝试通过已与Mac配对的Windows端Visual Studio,将首个MAUI应用以Debug模式部署到iPhone真机,但遇到以下错误,该应用在iPhone模拟器中运行正常。
错误信息
[0:] 发生错误:无法创建类型'DevExpress.iOS.Editors.DXTextEdit'的原生实例:原生类尚未加载。 可以通过设置ObjCRuntime.Class.ThrowOnInitFailure为false来忽略此条件。 调用栈: at Foundation.NSObject.InitializeObject(Boolean alloced) at Foundation.NSObject..ctor(NSObjectFlag x) at UIKit.UIResponder..ctor(NSObjectFlag t) at UIKit.UIView..ctor(NSObjectFlag t) at DevExpress.iOS.Editors.DXTextEditBase..ctor(NSObjectFlag t) at DevExpress.iOS.Editors.DXTextEdit..ctor() at DevExpress.Maui.Editors.Internal.TextEditHandler.CreateNativeView() at DevExpress.Maui.Core.iOS.Internal.DXViewHandler`2[[DevExpress.Maui.Editors.TextEdit, DevExpress.Maui.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a],[DevExpress.iOS.Editors.DXTextEdit, DevExpress.iOS.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a]].CreatePlatformView() at Microsoft.Maui.Handlers.ViewHandler`2[[DevExpress.Maui.Editors.TextEdit, DevExpress.Maui.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a],[DevExpress.iOS.Editors.DXTextEdit, DevExpress.iOS.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a]].OnCreatePlatformView() at Microsoft.Maui.Handlers.ViewHandler.OnCreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement() at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler`2[[DevExpress.Maui.Editors.TextEdit, DevExpress.Maui.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a],[DevExpress.iOS.Editors.DXTextEdit, DevExpress.iOS.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[DevExpress.Maui.Editors.TextEdit, DevExpress.Maui.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a],[DevExpress.iOS.Editors.DXTextEdit, DevExpress.iOS.Editors, Version=23.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.BorderHandler.UpdateContent(IBorderHandler handler) at Microsoft.Maui.Handlers.BorderHandler.MapContent(IBorderHandler handler, IBorderView border) at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IBorderView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IBorderHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IBorderView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.BorderHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IBorderView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
应用已终止。
解决步骤
确认DevExpress包引用与嵌入
检查项目的.csproj文件,确保已正确引用对应版本的DevExpress.Maui.Editors包:<ItemGroup> <PackageReference Include="DevExpress.Maui.Editors" Version="23.1.5" /> </ItemGroup>执行清理解决方案 -> 重新生成解决方案,确保原生库文件被正确传输到Mac构建主机。
提前加载原生类
在App.xaml.cs的OnStart方法中添加代码,强制提前加载DXTextEdit类,避免运行时加载失败:using ObjCRuntime; using DevExpress.iOS.Editors; protected override void OnStart() { // 预加载原生类,确保运行时可访问 Class.GetHandle(typeof(DXTextEdit)); }临时绕过初始化异常(仅用于排查)
如果上述方法无效,可临时关闭初始化失败的异常抛出(不推荐长期使用,避免隐藏其他问题):using ObjCRuntime; protected override void OnStart() { Class.ThrowOnInitFailure = false; }检查Mac构建环境
确保Mac上安装的Xcode版本与MAUI要求兼容,且DevExpress的iOS组件已正确部署。可尝试在Mac端直接打开项目的iOS工程,编译运行一次,确认没有依赖缺失。重新配对Windows与Mac
断开Visual Studio与Mac的配对连接,重新建立配对,避免因连接不稳定导致构建过程中库文件传输不完整。
内容的提问来源于stack exchange,提问作者Y U
相关产品推荐
相关产品推荐

