Closed dotMorten closed 4 years ago
Update: I narrowed it down a bit more. Instead of creating the MapView
control, I instead create this:
var l = new Esri.ArcGISRuntime.Location.SystemLocationDataSource();
The issue still reproduces. But the weird part is if you then take this repro and bring it into a .NET Core console app, it no longer reproduces. There seems to be some weird thing going on between my library and WPF.
So that class doesn't really do much in the constructor. Having said that I do use reflection to get to the WinRT Geolocator types in that class (the thing that now no longer works in net5, so this returns null).
However, after realizing that Type.GetType("Windows.Devices.Geolocation.Geolocator, Windows, ContentType=WindowsRuntime");
returns null, it doesn't really do anything else. I've tried that line of code in the repro, and it doesn't seem to trigger the problem.
@dotMorten I'm seeing a Windows.Devices.Geolocation.Geoposition type in the ArcGIS.Runtime assembly. It looks like the type discovery algorithm C#/WinRT uses for parsing the runtime class name is accidentally picking up that type instead of the type in the projection.
Based on this, we need to fix #312 or complete #369 to fix this issue.
If the Windows.Devices.Geolocation.Geoposition
type in ArcGIS.Runtime
is just a reflection-based wrapper around the WinRT object in the old system and you can #if
it away on .NET 5, then that should work as a workaround for this issue.
@jkoritzinsky I could do that, but that would require adding a .NET 5 target and shipping a new release which is some ways out in the future. Also how come when adding that line of code in the app itself doesn't cause this to get reproduced?
Second, do I understand your first comment correctly that this isn't technically a bug in my code, but a bug in CsWinRT? It definitely seems odd that a simple type lookup can cause the entire projection to stop working. I'm assuming I have far from the only existing library out there that does this, and would break .NET 5 interop.
Yes this is a bug in C#/WinRT. It only fails if the ArcGIS.Runtime assembly is loaded in such a way that it is earlier in the runtime's list of loaded assemblies than Microsoft.Windows.SDK.NET.dll.
That's why it doesn't happen when you don't use the ArcGIS APIs before calling into the WinRT APIs.
I can confirm that if I add this line to the App constructor to cause it to load, it'll work:
public App()
{
var locator = new Geolocator();
}
I'm seeing a Windows.Devices.Geolocation.Geoposition type in the ArcGIS.Runtime assembly
Yes I wrote an internal wrapper the matches the API of the WinRT API I used in the UWP target so I had less code-differences between .NET Core and UWP in the consuming code. I guess a simple solution would be to just change the namespace, but again that wouldn't be until we ship the next version, and at that point, I expect we have moved to the new way for consuming WinRT types.
Tagging for RTM - Part of this should be fixed with IDynamicInterfaceCastable and the other part is handled by Module Initializers
This one has me quite stumped. The WinRT breaking change for .NET5 affects us, since we use the GeoLocator on Win8+ via reflection into the WinRT APIs, so I set out to build a workaround for our customers using the new projections instead. To my surprise, getting a position from the locator like this:
would throw:
So I set out to make a reproducer, and couldn't repro. What I found is that when I add a reference to my WPF Control Library, and add that control to the view, the problem occurs. If I just instantiate the control but don't add it to the view, it works.
Repro: Repro app:WpfApp1.zip Or: Create a new WPF project and add the Esri control package:
csproj:
Add the following code to
MainWindow.xaml.cs
(note: I named the root Grid controlLayoutRoot
inMainWindow.xaml
)Observe the exception in GetLocation getting caught. Next remove the call
this.Content = mapView;
, and observe getting the location works.Unfortunately I can't share the source for the control, but I can't really spot anything especially weird that takes place in Load/OnApplyTemplate that seems to trigger this issue - I'd be happy to troubleshoot one-on-one on a call as well so we can pinpoint the culprit. The static initializers and constructor does cause some code to run that could potentially cause this, but calling the constructor doesn't seem to cause the problem to appear.