Hi,
I built a single-file executable in .NET with the following command for my application using ArcGIS Runtime.
dotnet publish -r win-x64But 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>
Solved! Go to Solution.
<Target Name="CopyShapefiles" AfterTargets="Build;Publish">
<ItemGroup>
<ShapefileComponents Include="data\**\*.shp;data\**\*.dbf;data\**\*.shx;data\**\*.prj;data\**\*.cpg" />
</ItemGroup>
<!-- Copy to output directory (for when building without publishing) -->
<Copy SourceFiles="@(ShapefileComponents)"
DestinationFolder="$(OutputPath)%(RelativeDir)"
SkipUnchangedFiles="true" />
<!-- Copy to publish directory (only applies to published builds) -->
<Copy SourceFiles="@(ShapefileComponents)"
DestinationFolder="$(PublishDir)%(RelativeDir)"
SkipUnchangedFiles="true" />
</Target>
var baseDir = AppContext.BaseDirectory;var baseDir = Path.GetDirectoryName(System.Environment.ProcessPath);
<Target Name="CopyShapefiles" AfterTargets="Build;Publish">
<ItemGroup>
<ShapefileComponents Include="data\**\*.shp;data\**\*.dbf;data\**\*.shx;data\**\*.prj;data\**\*.cpg" />
</ItemGroup>
<!-- Copy to output directory (for when building without publishing) -->
<Copy SourceFiles="@(ShapefileComponents)"
DestinationFolder="$(OutputPath)%(RelativeDir)"
SkipUnchangedFiles="true" />
<!-- Copy to publish directory (only applies to published builds) -->
<Copy SourceFiles="@(ShapefileComponents)"
DestinationFolder="$(PublishDir)%(RelativeDir)"
SkipUnchangedFiles="true" />
</Target>
var baseDir = AppContext.BaseDirectory;var baseDir = Path.GetDirectoryName(System.Environment.ProcessPath);Thanks for your help — that solved my issue. @imalcolm_esri