From 85cf0483ec6e133f753193a6e36b03056cba2b1f Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Thu, 12 Sep 2024 13:13:51 +0200 Subject: [PATCH] throw ArgumentException when projection could not be created --- MapControl/Shared/GeoImage.cs | 2 +- MapUiTools/Shared/MapProjectionsMenuButton.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs index a76a8b6e..66d21165 100644 --- a/MapControl/Shared/GeoImage.cs +++ b/MapControl/Shared/GeoImage.cs @@ -166,7 +166,7 @@ namespace MapControl var epsgCode = geoKeyDirectory[i + 3]; mapProjection = MapProjectionFactory.Instance.GetProjection($"EPSG:{epsgCode}") ?? - throw new ArgumentException($"Can not create projection EPSG:{epsgCode}."); + throw new ArgumentException($"Can not create MapProjection \"EPSG:{epsgCode}\"."); } } } diff --git a/MapUiTools/Shared/MapProjectionsMenuButton.cs b/MapUiTools/Shared/MapProjectionsMenuButton.cs index bb2301b5..302e5477 100644 --- a/MapUiTools/Shared/MapProjectionsMenuButton.cs +++ b/MapUiTools/Shared/MapProjectionsMenuButton.cs @@ -2,6 +2,7 @@ // Copyright © 2024 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) +using System; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; @@ -25,7 +26,7 @@ namespace MapControl.UiTools { #if WPF [ContentProperty(nameof(Projection))] - #elif UWP || WINUI +#elif UWP || WINUI [ContentProperty(Name = nameof(Projection))] #endif public class MapProjectionItem @@ -101,7 +102,8 @@ namespace MapControl.UiTools if (selectedProjection != projection) { selectedProjection = projection; - Map.MapProjection = MapProjectionFactory.Instance.GetProjection(selectedProjection); + Map.MapProjection = MapProjectionFactory.Instance.GetProjection(selectedProjection) ?? + throw new ArgumentException($"Can not create MapProjection \"{selectedProjection}\"."); } UpdateCheckedStates();