Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error publishing a single executable #483

Closed
IlluminatiWave opened this issue Dec 27, 2022 · 8 comments
Closed

Error publishing a single executable #483

IlluminatiWave opened this issue Dec 27, 2022 · 8 comments
Labels
bug Something isn't working locked-due-to-inactivity

Comments

@IlluminatiWave
Copy link

IlluminatiWave commented Dec 27, 2022

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@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

@IlluminatiWave IlluminatiWave added the bug Something isn't working label Dec 27, 2022
@Aybex
Copy link
Contributor

Aybex commented Jan 7, 2023

I can confirm, I have just encountered this problem

  • Visual studio 2022
  • WPF-UI 2.0.3
  • .NET 7
    Other Nuget packages :
  • CommunityToolkit.Mvvm 8.0.0
  • Microsoft.Extensions.Hosting 7.0.0
  • LiveChartsCore.SkiaSharpView.WPF 2.0.0-beta.700

@IvanDmitriev1
Copy link
Collaborator

Well, the gallery and demo projects doesn't start in the development branch either

@IvanDmitriev1
Copy link
Collaborator

IvanDmitriev1 commented Jan 17, 2023

The problem was in this line, the Location property was null.

image

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>

The .Net Runtime source in the event viewer has a better error details

image

@IlluminatiWave
Copy link
Author

Well, the gallery and demo projects doesn't start in the development branch either

Any suggestions on how to detect that the same executable is the directory?

(I tried to make it accept null values and the problem persists)

By the way, compiling gallery and demo (unmodified) in normal mode (with its libraries) works perfectly.

@Aybex
Copy link
Contributor

Aybex commented Jan 18, 2023

By the way, compiling gallery and demo (unmodified) in normal mode (with its libraries) works perfectly.

Does publishing the Demo.Mvvm work for you ? I experienced the same problem with it .

  1. I got the latest commit code From the development branch
  2. I Built the Demo.Mvvm in Release
  3. In the project folder I run dotnet publish with the following command :
    dotnet publish .\Wpf.Ui.Demo.Mvvm.csproj -p:PublishSingleFile=true -c Release -a x64 -o ./bin/publish
  4. The publish execute just fine but the 'WPF UI - MVVM Demo.exe' won't run now
    image

@MrCosmo
Copy link

MrCosmo commented 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

pomianowski added a commit that referenced this issue Jan 23, 2023
Fixed app published as singleFile not running (issue #483)
@IlluminatiWave
Copy link
Author

Wow, the solution worked. Sorry for the delay (and I hope this reply is not too long).


¿La publicación de Demo.Mvvm funciona para usted? Experimenté el mismo problema con él.

  1. Obtuve el último código de confirmación de la rama de desarrollo
  2. Construí el Demo.mvvm en versión
  3. En la carpeta del proyecto ejecuto dotnet publish con el siguiente comando:
    dotnet publish .\Wpf.Ui.Demo.Mvvm.csproj -p:PublishSingleFile=true -c Release -a x64 -o ./bin/publish
  4. La publicación se ejecuta bien, pero la 'WPF UI - MVVM Demo.exe' no se ejecutará ahora
    imagen

No, I created a new project from Visual Studio itself (the plug-in installed in the IDE allows you to create projects with wpf integrated by default. current version 2.0.3).

image


Solucioné este problema estableciendo la siguiente configuración: Este código se puede encontrar en App.xaml.csBasePath``.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })

Thanks :0

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 )


7021685

I really don't feel comfortable touching other people's code, thanks for adding the fix to Wpf.Ui.Demo.Mvvm/App.xaml.cs, but the error continues in these other files (The first 3 are related to the VS plugin):

@Aybex
Copy link
Contributor

Aybex commented 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.

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  or throws an exception.
Marshal.GetHINSTANCE Returns -1.
Module.Name Returns a string with the value of .

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working locked-due-to-inactivity
Projects
None yet
Development

No branches or pull requests

5 participants