Cannot create SpatialReference with 100.7 in .NET Core 3.1

751
2
01-17-2020 12:06 PM
JasonDick
New Contributor II

Title. Works fine in .NET Framework 4.8. Created a new project to double-check. Confirmed 100.6 does work.

Sub Main()
   Dim loSRS As SpatialReference
   loSRS = SpatialReference.Create(26915)
End Sub

System.InvalidOperationException
  HResult=0x80131509
  Message=Invalid Wkid value creating a SpatialReference.
  Source=Esri.ArcGISRuntime
  StackTrace:
   at Esri.ArcGISRuntime.Geometry.SpatialReference.CreateCoreCheckParams(Int32 wkid, Int32 vertId)
   at Esri.ArcGISRuntime.Geometry.SpatialReference.Create(Int32 wkid, Int32 verticalWkid)
   at Esri.ArcGISRuntime.Geometry.SpatialReference.Create(Int32 wkid)
   at ConsoleApp2.Module1.Main() in C:\Temp\ConsoleApp2\ConsoleApp2\Program.vb:line 7

Inner Exception 1:
TypeInitializationException: The type initializer for 'RuntimeCoreNet.GeneratedWrappers.CoreSpatialReference' threw an exception.

Inner Exception 2:
TypeLoadException: Could not load type 'System.Windows.DependencyProperty' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

0 Kudos
2 Replies
dotMorten_esri
Esri Frequent Contributor

Since .NET Core is only supported on Windows Desktop and relies on WindowsBase, make sure you use the enable those features in your project.

In .csproj, set the project SDK to:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

You might also have to declare <UseWpf>true</UseWpf> in a property group. 

0 Kudos
JasonDick
New Contributor II

Argh, that worked. This sounds familiar. I was using a Console app since I was just doing performance testing.

0 Kudos