VS中C#调试出现断点,球球帮改

VS中C#调试断点,求大神帮改为中断点,继续调试的话则出现下图断点和警告(代码断点-图中代码断点-警告)

img

img



using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.UI;

namespace Coordinate_DX21232;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        this.BindingContext = new MapViewModel();
    }

    private void mapView_GeoViewDoubleTapped(object sender, GeoViewInputEventArgs e)
    {
        
        MapPoint mapLocation = e.Location;
       
        Esri.ArcGISRuntime.Geometry.Geometry myGeometry = GeometryEngine.Project(mapLocation, SpatialReferences.Wgs84);
        
        MapPoint projectedLocation = (MapPoint)myGeometry;
        //callout显示字符串
**        string mapLocationDesription = string.Format("经度:{0:F7}纬度:{1:F7}", projectedLocation.X, projectedLocation.Y);**
       
        CalloutDefinition myCalloutDefinition = new CalloutDefinition("位置", mapLocationDesription);
        
        mapView.ShowCalloutAt(mapLocation, myCalloutDefinition);
    }
}






System.FormatException
  HResult=0x80131537
  Message=Input string was not in a correct format.
  Source=System.Private.CoreLib
  StackTrace:
   在 System.Text.ValueStringBuilder.ThrowFormatInvalidString()
   在 System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   在 System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   在 System.String.Format(String format, Object arg0, Object arg1)
   在 Coordinate_DX21232.MainPage.mapView_GeoViewDoubleTapped(Object sender, GeoViewInputEventArgs e) 在 D:\visualstudio2022\练习\GIS应用开发2\Coordinate_DX21232\Coordinate_DX21232\MainPage.xaml.cs 中: 第 24 行
   在 Esri.ArcGISRuntime.Maui.GeoView.Esri.ArcGISRuntime.Maui.IGeoView.GeoViewDoubleTapped(GeoViewInputEventArgs e)
   在 Esri.ArcGISRuntime.Maui.Handlers.GeoViewHandler`2.OnGeoViewDoubleTapped(Object sender, GeoViewInputEventArgs e)
   在 Esri.ArcGISRuntime.UI.Controls.GeoView.OnGeoViewDoubleTapped(Point screenLocation, DeviceIndependentPointingDevice device)
   在 Esri.ArcGISRuntime.UI.Controls.MapView.OnGeoViewDoubleTapped(Point screenLocation, DeviceIndependentPointingDevice device)
   在 Esri.ArcGISRuntime.UI.UserInteractionHandler.OnDoubleTapped(Point screenLocation, DeviceIndependentPointingDevice device)
   在 Esri.ArcGISRuntime.UI.StoreDeviceInteractionHandler.DoubleTapped(Object sender, DoubleTappedRoutedEventArgs e)
   在 WinRT._EventSource_global__Microsoft_UI_Xaml_Input_DoubleTappedEventHandler.EventState.<GetEventInvoke>b__1_0(Object sender, DoubleTappedRoutedEventArgs e)
   在 ABI.Microsoft.UI.Xaml.Input.DoubleTappedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)

你遇到的错误 System.FormatException 通常是由 string.Format 方法中的格式说明符不正确引起的。 在你的代码中,您使用格式说明符 F7 来格式化经度和纬度值。 但是,具有 7 个小数位的浮点数的正确格式说明符是 F7,而不是 F7(在 F7 之前有一个空格)。

要修复此错误,请删除 string.Format 方法中 F7 之前的空格。

经度:{0:F7}纬度:{1:F7} 调整为 经度:{0:F7}纬度:{1:F7}
不要用中文 :

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7590051
  • 这篇博客你也可以参考下:理解vs解决方案和项目 一些c#入门知识
  • 除此之外, 这篇博客: C# 多线程学习 (一)--- 线程池VS任务中的 等待 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
    var task = Task.Run(() => Console.WriteLine("Start Task"));
    //显式阻塞当前线程,等待task执行完毕
    task.Wait();
    
  • 您还可以看一下 张建飞老师的C#急速入门课程中的 VS中的断点调试小节, 巩固相关知识点
  • 以下回答来自chatgpt:

    针对Visual Studio调试中出现的断点和警告问题,可以采取以下措施进行优化和解决: 1. 断点问题解决:可能是因为在调试过程中添加了断点,但是代码没有正确执行,可以通过以下方式解决: - 设置断点时,注意选择正确的代码行; - 检查代码是否存在语法错误或逻辑错误; - 避免在代码块中添加过多的断点; - 尝试重新启动Visual Studio,或重置IDE的设置。 2. 警告问题解决:可能是因为代码中存在一些不规范或不严谨的写法,可以通过以下方式解决: - 仔细阅读警告信息,确定所在代码块; - 对照代码规范检查代码是否存在问题; - 可以尝试在代码中添加一些注释优化代码; - 对于一些黄色警告,可以不必处理,但红色警告必须及时修复。 以上是一些常见的解决方法,但具体情况需要根据实际代码情况进行分析,并根据错误信息进行优化和解决。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^