ThinkGeo.com    |     Documentation    |     Premium Support

Visual Studio crashes after trying to insert MapView from ToolBox

Project .NET version: 6.0

I’m trying to replicate the OSM overlay sample on my app and when I try to insert a MapView (from ThinkGeo.UI.WinForms), after setting the map size, Visual Studio crashes and restarts.

Visual Studio version: 17.4.2

Output log:

[13:39:46.931174] warn: [Agregador]: Could not resolve type for System.ComponentModel.Design.Serialization.TypeCodeDomSerializer .
[13:39:47.667091] fail: [Agregador]: Unhandled exception. System.ArgumentOutOfRangeException: The value for the enumeration is not one of the valid values. (Parameter 'mapUnit')
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.ValidatorHelper.CheckGeographyUnitIsValid(GeographyUnit geographyUnit, String parameterName)
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.MapUtil.GetScale(GeographyUnit mapUnit, RectangleShape boundingBox, Double widthInPixel, Double heightInPixel, Single dpi)
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.MapUtil.bx0=(RectangleShape targetExtent, Single actualWidth, Single actualHeight, Double maximumScale, Double minimumScale, GeographyUnit mapUnit)
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.MapUtil.AdjustExtentByRestrictions(RectangleShape targetExtent, Single width, Single height, RectangleShape restrictExtent, Double maximumScale, Double minimumScale, GeographyUnit mapUnit)
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.MapViewBase.DrawCore(RectangleShape targetExtent, OverlayRefreshType overlayRefreshType)
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.MapViewBase.Draw(RectangleShape targetExtent, OverlayRefreshType refreshType)
[13:39:47.667091] fail: [Agregador]:    at ThinkGeo.Core.MapViewBase.MEU=(Object sender, EventArgs e)
[13:39:47.667091] fail: [Agregador]:    at System.Windows.Threading.DispatcherTimer.FireTick()
[13:39:47.668088] fail: [Agregador]:    at System.Windows.Threading.DispatcherTimer.<>c.<Restart>b__21_0(Object state)
[13:39:47.668088] fail: [Agregador]:    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
[13:39:47.668088] fail: [Agregador]:    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
[13:39:47.668088] fail: [Agregador]:    at System.Windows.Threading.DispatcherOperation.InvokeImpl()
[13:39:47.668088] fail: [Agregador]:    at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
[13:39:47.668088] fail: [Agregador]:    at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
[13:39:47.668088] fail: [Agregador]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[13:39:47.668088] fail: [Agregador]: --- End of stack trace from previous location ---
[13:39:47.668088] fail: [Agregador]:    at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
[13:39:47.668088] fail: [Agregador]:    at System.Windows.Threading.DispatcherOperation.Invoke()
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Threading.Dispatcher.ProcessQueue()
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
[13:39:47.669087] fail: [Agregador]:    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
[13:39:47.669087] fail: [Agregador]:    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
[13:39:47.669087] fail: [Agregador]:    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
[13:39:47.669087] fail: [Agregador]:    at Interop.User32.DispatchMessageW(MSG& msg)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
[13:39:47.669087] fail: [Agregador]:    at System.Windows.Forms.Application.Run(ApplicationContext context)
[13:39:47.669087] fail: [Agregador]:    at Microsoft.DotNet.DesignTools.Server.DesignToolsServer.<>c__DisplayClass54_0.<StartUIThreadAsync>b__1()
[13:39:47.669087] fail: [Agregador]:    at System.Threading.Thread.StartHelper.Callback(Object state)
[13:39:47.669087] fail: [Agregador]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[13:39:47.670087] fail: [Agregador]: --- End of stack trace from previous location ---
[13:39:47.670087] fail: [Agregador]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[13:39:47.670087] fail: [Agregador]:    at System.Threading.Thread.StartCallback()
[13:39:51.229073] warn: Cannot update selection in server process as Session is not connected.
[13:39:51.388274] warn: Cannot update selection in server process as Session is not connected.

Hey @Gabriel_Amado,

This is somewhat related to your other thread with the sample itself. This crash is happening because the MapUnit is not set in the designer code. When you add the MapView to the app, set the MapUnit property to a valid value. Alternatively, you can set it in the designer code itself, much like I describe in your other thread.

Thanks,
Kyle

1 Like

Yup! I noticed the same output log.

But unlike the sample, my designer isn’t generating the MapView object properties in order for me to edit them. When I manage to keep Visual Studio open after the crash, there’s no MapView object in the designer. It’s like it’s not instantiating a MapView object (user control, from the toolbox) in the design.

Is there a way I can instantiate a MapView from within the designer.cs? I tried just doing:

private ThinkGeo.UI.WinForms.MapView mapView;

and copying the designer properties from the sample, but no good. It’s like I said, after it crashes it kinda deletes the element from the design so there’s nothing in the designer.cs file.

Hey @Gabriel_Amado,

Yes, you can copy the designer properties, but you have to have specific parts of it to stick around. Here’s a screenshot for reference:

You already had the private MapView, but then you’ll need to create the MapView object in the InitializeComponent method and then set the properties. Then add it to the controls collection and then resume layout at the very end. Here’s the code in text form as well:

private MapView mapView;

private void InitializeComponent()
{
    this.mapView = new ThinkGeo.UI.WinForms.MapView();
    this.SuspendLayout();
    // 
    // mapView
    // 
    this.mapView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    | System.Windows.Forms.AnchorStyles.Left)
    | System.Windows.Forms.AnchorStyles.Right)));
    this.mapView.BackColor = System.Drawing.Color.White;
    this.mapView.CurrentScale = 0D;
    this.mapView.Location = new System.Drawing.Point(0, 0);
    this.mapView.MapResizeMode = ThinkGeo.Core.MapResizeMode.PreserveScale;
    this.mapView.MapUnit = ThinkGeo.Core.GeographyUnit.Meter;
    this.mapView.MaximumScale = 1.7976931348623157E+308D;
    this.mapView.MinimumScale = 200D;
    this.mapView.Name = "mapView";
    this.mapView.RestrictExtent = null;
    this.mapView.RotatedAngle = 0F;
    this.mapView.Size = new System.Drawing.Size(1077, 610);
    this.mapView.TabIndex = 0;

    this.Controls.Add(this.mapView);
    components = new System.ComponentModel.Container();
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ResumeLayout(false);
}

As a side note, this is not usual behavior. The reason this needs to be like this is a combination of the HowDoI project being a hybrid Framework/.NET6 project and the way VS2022 treats them. When you create your own application, you should be able to drag the control in normally without all these hoops.

Thanks,
Kyle

1 Like

Thanks for the help and patience.

Hey @Gabriel_Amado,

You’re welcome and good luck!

Thanks,
Kyle