question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error publishing a single executable

See original GitHub issue

Describe the bug

When publishing an application with the “produce a single file” publishing setting enabled, the published application (.exe) doesn’t open. The event viewer shows the following error

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
	<System>
		<Provider Name="Application Error" Guid="{a0e9b465-b939-57d7-b27d-95d8e925ff57}" /> 
		<EventID>1000</EventID> 
		<Version>0</Version> 
		<Level>2</Level> 
		<Task>100</Task> 
		<Opcode>0</Opcode> 
		<Keywords>0x8000000000000000</Keywords> 
		<TimeCreated SystemTime="2022-12-27T17:18:37.9947560Z" /> 
		<EventRecordID>4695</EventRecordID> 
		<Correlation /> 
		<Execution ProcessID="25028" ThreadID="22632" /> 
		<Channel>Application</Channel> 
		<Computer>DESKTOP-ED46SDN</Computer> 
		<Security UserID="S-1-5-21-1370086028-2928665489-3087911640-1003" /> 
	</System>
	<EventData>
		<Data Name="AppName">UiDesktopApp1.exe</Data> 
		<Data Name="AppVersion">1.0.0.0</Data> 
		<Data Name="AppTimeStamp">6377dc84</Data> 
		<Data Name="ModuleName">KERNELBASE.dll</Data> 
		<Data Name="ModuleVersion">10.0.25267.1000</Data> 
		<Data Name="ModuleTimeStamp">7b673108</Data> 
		<Data Name="ExceptionCode">e0434352</Data> 
		<Data Name="FaultingOffset">000000000003b77c</Data> 
		<Data Name="ProcessId">0x3fd8</Data> 
		<Data Name="ProcessCreationTime">0x1d91a174175962f</Data> 
		<Data Name="AppPath">%USERPROFILE%\Downloads\pub\UiDesktopApp1.exe</Data> 
		<Data Name="ModulePath">C:\WINDOWS\System32\KERNELBASE.dll</Data> 
		<Data Name="IntegratorReportId">a4c17f60-a25d-4b78-857b-db5faf6119a0</Data> 
		<Data Name="PackageFullName" /> 
		<Data Name="PackageRelativeAppId" /> 
	</EventData>
</Event>

When publishing as a single file, I get several errors related to variables that do not accept NULL values

The field element "_navigationWindow" that doesn't accept NULL values must contain a value other than NULL when exiting the constructor. Consider declaring the field element as accepting a NULL value.

My assumption is, that being a single file, the system is not prepared to run as a single file, as it will always try to read the wpf.ui libraries externally (.dll).

To Reproduce

  1. Create or open your solution
  2. In the solution exporter, right click on the application and select publish. image
  3. In the publish tab, configure the publication, you have to select any target runtime environment to any one that is not “portable” (In my case win-x64, although it also happens with x86. I do not know if it also happens with other systems like Linux).
  4. When selecting any that is not portable, extra options appear, you have to check the box to produce a single file and save. image
  5. Publish and run image

PS: My language is Spanish PS 2: %userprofile% is actually C:\Users\ [my user]

Expected behavior

Program to run (open normally)

Screenshots

No response

OS version

OS: Win 11 Ver. 0.0.25267 build 25267 (insider)

.NET version

Microsoft Visual Studio Community 2022 Versión 17.4.3 VisualStudio.17.Release/17.4.3+33205.214 Microsoft .NET Framework Versión 4.8.09032

Versión instalada: Community

Visual C++ 2022 00482-90000-00000-AA468

Adaptador de prueba para Boost.Test 1.0

ADL Tools Service Provider 1.0

Administrador de paquetes NuGet 6.4.0

ASA Service Provider 1.0

ASP.NET and Web Tools 17.4.326.54890ASP.NET and Web Tools

Azure Data Lake Tools for Visual Studio 2.6.5000.0

Azure Functions and Web Jobs Tools 17.4.326.54890

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0

Cookiecutter 17.0.22263.6

Depuración de volcados de memoria básicos de Linux 1.0.9.33020

Dotfuscator Community Edition 6.5.0+76d4669002

Extensibility Message Bus 1.4.1 (main@2ee106a)

Extensión de VSPackage 1.0

Herramientas comunes de Windows Azure 1.10

Herramientas de Azure App Service v3.0.0 17.4.326.54890

Herramientas de C# 4.4.0-6.22580.4+d7a61210a88b584ca0827585ec6e871c6b1c5a14

Herramientas de Node.js 1.5.40817.1 Commit Hash:66443775f9f3b1d8f8fee47af5002828b346688d

Herramientas de TypeScript 17.0.10921.2001

Herramientas de Visual Basic 4.4.0-6.22580.4+d7a61210a88b584ca0827585ec6e871c6b1c5a14

Herramientas de Visual F# 17.4.0-beta.22512.4+525d5109e389341bb90b144c24e2ad1ceec91e7b

Microsoft Azure Hive Query Language Service 2.6.5000.0

Microsoft Azure Stream Analytics Language Service 2.6.5000.0

Microsoft JVM Debugger 1.0

Mono Debugging for Visual Studio 17.4.19 (8c0a575)

Python con Pylance 17.0.22263.6

Python: compatibilidad con proyectos de VC 17.0.21344.1

Python: compatibilidad de Django 17.0.22263.6

Python: compatibilidad de la generación de perfiles 17.0.22263.6

Razor (ASP.NET Core) 17.0.0.2246202+61cc048d36a3fc9246d2f04625988b19a18ab8f0

SQL Server Data Tools 17.0.62207.28050

Test Adapter para Google Test 1.0

ToolWindowHostedEditor 1.0

Visual C++ for Linux Development 1.0.9.33020

Visual Studio IntelliCode 2.2

Visual Studio Tools para Unity 17.4.3.0

VisualStudio.DeviceLog 1.0

VisualStudio.Mac 1.0

Xamarin 17.4.0.312 (d17-4@be7e8d1)

Xamarin Designer 17.4.0.138 (remotes/origin/d17-4@d36bba3cc9)

Xamarin Templates 17.4.2 (c457c97)

Xamarin.Android SDK 13.1.0.1 (d17-4/13ba222) Mono: a96bde9 Java.Interop: xamarin/java.interop/d17-4@fcc33ce2 SQLite: xamarin/sqlite/3.39.3@23e1ae7 Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a

Xamarin.iOS and Xamarin.Mac SDK 16.1.1.27 (933c6c2c9)

WPF-UI NuGet version

2.0.3

Additional context

No response

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
MrCosmocommented, Jan 19, 2023

I fixed this issue by setting the setting the BasePath as follows: .ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); }) This code can be found in App.xaml.cs

1reaction
Aybexcommented, Feb 5, 2023

By the way, What’s the difference between AppContext.BaseDirectory and Assembly.GetEntryAssembly() From what I looked up, BaseDirectory Returns the path to the folder where the executable was launched, but the explanation about Assembly was not clear to me (it seems confusing :C )

According to Microsoft :

Some APIs aren’t compatible with single file deployment The table below has the relevant runtime library API details for single file use.

<html> <body>
API Note
Assembly.CodeBase Throws PlatformNotSupportedException.
Assembly.EscapedCodeBase Throws PlatformNotSupportedException.
Assembly.GetFile Throws IOException.
Assembly.GetFiles Throws IOException.
Assembly.Location Returns an empty string.
AssemblyName.CodeBase Returns null.
AssemblyName.EscapedCodeBase Returns null.
Module.FullyQualifiedName Returns a string with the value of <Unknown> or throws an exception.
Marshal.GetHINSTANCE Returns -1.
Module.Name Returns a string with the value of <Unknown>.
</body> </html>

About other files, the gallery code is already changed in the development branch, and for the extensions, I think a deeper refactor should be done to adapt them to the new navigation system in version 3.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

roslyn - .NET 5 not compiling to single file executables
For .NET 5, to get a single runnable executable file when you publish your project, the important properties are:.
Read more >
Resolved- NETSDK1099: Publishing to a single-file is only ...
Issue resolution for error NETSDK1099: Publishing to a single-file is only supported for executable applications. Run commands against executable ...
Read more >
Publish single executable not working for .NET 5 or .NET 6
Solved: Publishing a WPF application as a single executable does not work for .NET 5 (using ArcGIS Runtime 100.12) or .
Read more >
Self-Contained Single-File does not produce a single file
I have set it up to publish as a self-contained single-file. However, in the publish directory is the EXE file and four DLLs....
Read more >
PublishSingleFile=true does not result in a true single-file ...
When publishing a single-file, self-contained .NET 5 executable, the resulting published files are not a true single-file output.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found