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

.NET MAUI使用Microsoft.Maui.Controls.Maps触发未处理异常

.NET MAUI地图控件添加后触发App.g.i.cs未处理异常

我在.NET MAUI应用中尝试实现地图功能,使用Microsoft.Maui.Controls.Maps提供的地图控件,但将该控件添加到XAML视图后,总是会在生成文件App.g.i.cs中触发未处理异常。

我已在.NET 6和.NET 7环境中进行尝试,均无法正常运行。使用的库版本如下:

  • Microsoft.Maui.Controls.Maps => 7.0.49
  • Microsoft.Maui.Maps => 7.0.49

我多次尝试更改库版本及运行时环境,但问题仍未解决。

触发异常的XAML视图源代码

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps"
             x:Class="RecargaEle.MainPage">

    <ScrollView>
        <VerticalStackLayout>
            <maps:Map/>
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

MauiProgram.cs代码

using CommunityToolkit.Maui;
using RecargaEle.Service.Implementacion;

namespace RecargaEle;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        
        builder
            .UseMauiApp<App>()
            .UseMauiCommunityToolkit()
            .UseMauiMaps()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
        builder.Services.AddSingleton<PuntosRecargaService>();
        return builder.Build();
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 06:05:18