We are experiencing an UWP issue related to Esri Runtime and Toolkit and having UWP libraries.
The issue occurs with Visual Studio 2019 (16.3.9, but newer versions show the same behavior as well).
Attached is a sample project. There is an UWP executable “esriuwp” that uses a class library “ClassLibrary1” that provides a user control that contains a simple Map Control. Nothing fancy.
The problem with this setup is: The application crashes when build this way.
Now it gets stranger than this. When I go to the properties of “ClassLibrary1” and change “Assembly name” and “Default namespace” from “ClassLibrary1” to “FClassLibrary1”, save the solution, exit it, delete obj and bin for both projects, re-open the solution, restore nuget and rebuild the projects again, everything will work as expected.
The details are: “ClassLibrary1” has a nuget Package to “Esri.ArcGISRuntime.Toolkit”, this is important. While this repro code does not necessarily need it, our production does. (If we would reference only the UWP runtime, the issue would not occur). The “esriuwp” executable project reference only “ClassLibrary1” and has no explicit dependency to Esri.
When the executable (not the class library!) is build, the compiler creates a file called “XamlTypeInfo.g.cs”. With “ClassLibrary1” called “ClassLibrary1”, the “OtherProviders” property is generated in this way:
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>System<SPAN class="punctuation token">.</SPAN>Collections<SPAN class="punctuation token">.</SPAN>Generic<SPAN class="punctuation token">.</SPAN>List<SPAN class="operator token"><</SPAN><SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="operator token">></SPAN> OtherProviders
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">get</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>_otherProviders <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> otherProviders <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>System<SPAN class="punctuation token">.</SPAN>Collections<SPAN class="punctuation token">.</SPAN>Generic<SPAN class="punctuation token">.</SPAN>List<SPAN class="operator token"><</SPAN><SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider provider<SPAN class="punctuation token">;</SPAN>
provider <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>ClassLibrary1<SPAN class="punctuation token">.</SPAN>ClassLibrary1_XamlTypeInfo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">XamlMetaDataProvider</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="punctuation token">;</SPAN>
otherProviders<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
provider <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Esri_ArcGISRuntime_Universal_XamlTypeInfo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">XamlMetaDataProvider</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="punctuation token">;</SPAN>
otherProviders<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
provider <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Toolkit<SPAN class="punctuation token">.</SPAN>Esri_ArcGISRuntime_Toolkit_XamlTypeInfo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">XamlMetaDataProvider</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="punctuation token">;</SPAN>
otherProviders<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
_otherProviders <SPAN class="operator token">=</SPAN> otherProviders<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> _otherProviders<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Three providers are created, ClassLibrary1 is first.
However, when „ClassLibrary1“ is renamed (Assembly name and Default namespace [although Default namespace is only for clarity]) to “FClassLibrary1”, the OtherProviders property looks similar, but FClassLibrary1 comes last now
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>System<SPAN class="punctuation token">.</SPAN>Collections<SPAN class="punctuation token">.</SPAN>Generic<SPAN class="punctuation token">.</SPAN>List<SPAN class="operator token"><</SPAN><SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="operator token">></SPAN> OtherProviders
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">get</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>_otherProviders <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> otherProviders <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>System<SPAN class="punctuation token">.</SPAN>Collections<SPAN class="punctuation token">.</SPAN>Generic<SPAN class="punctuation token">.</SPAN>List<SPAN class="operator token"><</SPAN><SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider provider<SPAN class="punctuation token">;</SPAN>
provider <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Esri_ArcGISRuntime_Universal_XamlTypeInfo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">XamlMetaDataProvider</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="punctuation token">;</SPAN>
otherProviders<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
provider <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Toolkit<SPAN class="punctuation token">.</SPAN>Esri_ArcGISRuntime_Toolkit_XamlTypeInfo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">XamlMetaDataProvider</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="punctuation token">;</SPAN>
otherProviders<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
provider <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>FClassLibrary1<SPAN class="punctuation token">.</SPAN>ClassLibrary1_XamlTypeInfo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">XamlMetaDataProvider</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Windows<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">.</SPAN>Xaml<SPAN class="punctuation token">.</SPAN>Markup<SPAN class="punctuation token">.</SPAN>IXamlMetadataProvider<SPAN class="punctuation token">;</SPAN>
otherProviders<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
_otherProviders <SPAN class="operator token">=</SPAN> otherProviders<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> _otherProviders<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The first version fails because looking up types often ends in „ClassLibrary1“, in which they exist but then fail to properly load.
Renaming changes the order in which UWP generates the type lookup and then everything is fine. Not referencing Toolkit but only ArcGisRuntime UWP effectively removes one of the three providers above (the Toolkit one) and when this happens “ClassLibrary1” loads fine even if it comes first.