Hi,
I built a single-file executable in .NET with the following command for my application using ArcGIS Runtime.
dotnet publish -r win-x64
But I can’t run the generated .exe with the following error message:
>Hello.exe
Unhandled exception. System.TypeInitializationException: The type initializer for 'Esri.ArcGISRuntime.Geometry.SpatialReferences' threw an exception.
---> System.InvalidOperationException: Invalid Wkid value (3857) creating a SpatialReference.
---> System.TypeInitializationException: The type initializer for 'RuntimeCoreNet.GeneratedWrappers.CoreSpatialReference' threw an exception.
---> System.DllNotFoundException: Dll was not found.
at RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.<CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory>g____PInvoke|69_0(Byte* __installPath_native, IntPtr* __outErrorHandle_native)
at RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.<CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory>g____PInvoke|69_0(Byte* __installPath_native, IntPtr* __outErrorHandle_native)
at RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory(String installPath, IntPtr* outErrorHandle)
at RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.SetInstallDirectory(String installPath)
at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.InitNative()
at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.InitializeRuntimeCore()
at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize()
at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.OnBeforeFirstUseOfGeneratedWrapper()
at RuntimeCoreNet.GeneratedWrappers.CoreSpatialReference..cctor()
--- End of inner exception stack trace ---
at RuntimeCoreNet.GeneratedWrappers.CoreSpatialReference..ctor(Int32 wkid)
at Esri.ArcGISRuntime.Geometry.SpatialReference.CreateCoreCheckParams(Int32 wkid, Int32 vertId)
--- End of inner exception stack trace ---
at Esri.ArcGISRuntime.Geometry.SpatialReference.CreateCoreCheckParams(Int32 wkid, Int32 vertId)
at Esri.ArcGISRuntime.Geometry.SpatialReference.GetFromCache(Int32 wkid, Int32 verticalWkid)
at Esri.ArcGISRuntime.Geometry.SpatialReference.Create(Int32 wkid, Int32 verticalWkid)
at Esri.ArcGISRuntime.Geometry.SpatialReferences..cctor()
--- End of inner exception stack trace ---
at Esri.ArcGISRuntime.Geometry.SpatialReferences.get_Wgs84()
at Hello.Program.Main() in C:\Users\*******\source\repos\MyArcSample\Program.cs:line 14
at Hello.Program.<Main>()
On the other hand, the executable produced by Build > Build {projectname} runs successfully.
So I’m wondering if I’m missing some configuration for the single-file build.
Do you have any ideas or hints on what could be causing this?
Thanks in advance.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DefaultItemExcludes>$(DefaultItemExcludes);tests\**\*;tests/**\*</DefaultItemExcludes>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Platforms>AnyCPU;x64;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Esri.ArcGISRuntime" Version="200.8.0" />
</ItemGroup>
<!-- Copy shapefile components from the data folder to output and publish directories -->
<ItemGroup>
<None Include="data\**\*.shp" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<None Include="data\**\*.dbf" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<None Include="data\**\*.shx" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<None Include="data\**\*.prj" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<None Include="data\**\*.cpg" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Project>