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

Self Contained application failed loads the output directory files #43014

Open
mageshsankar opened this issue Oct 4, 2020 · 9 comments
Open
Labels
area-Single-File question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@mageshsankar
Copy link

mageshsankar commented Oct 4, 2020

WPF Application crash when publish an Self Contained Exe

Description

Application Running on NetCore 5.0

I have published WPF application as Self Contained Exe, and it fails to load an document file(Build Action : Copy Always) so application crash on load document.

image

Issue:

  1. Self Contained application failed lods the output directory files
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Host untriaged New issue has not been triaged by the area owner labels Oct 4, 2020
@ghost
Copy link

ghost commented Oct 4, 2020

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

@mageshsankar mageshsankar changed the title WPF Application crash when publish an Self Contained Exe WPF Application crash when publish as Self Contained Exe Oct 4, 2020
@mageshsankar mageshsankar changed the title WPF Application crash when publish as Self Contained Exe Self Contained application failed lods the output directory files Oct 4, 2020
@mageshsankar mageshsankar changed the title Self Contained application failed lods the output directory files Self Contained application failed loads the output directory files Oct 4, 2020
@ghost
Copy link

ghost commented Oct 4, 2020

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@vitek-karas
Copy link
Member

Thanks for trying out single-file. Per the design document https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md in .NET 5 anything except managed code will not be bundled in the application and should be left next to the main .exe.

Can you please check that after publishing your application as single-file the .docx file is in the published folder next to the application executable?

If so, the right way to get to it from the code is to use AppContext.BaseDirectory which will point to the directory with the application executable.

Ideally if you want to always ship this file with your application it would be better to embed it as a resource to one of your managed assemblies and load it using the ResourceManager APIs. This approach will work the same regardless of how you publish your application.

@vitek-karas
Copy link
Member

vitek-karas commented Oct 4, 2020

Actually I thought this was a single-file publish - but you only mention self-contained. Can you please specify how you published your application? (ideally the command line or VS settings)

@mageshsankar
Copy link
Author

Hi @vitek-karas
image

image

image

I have used publish options using above method.

@vitek-karas
Copy link
Member

Thanks - in that case my comment about single-file should apply.

@mageshsankar
Copy link
Author

Hi @vitek-karas

which means self contained exe does not support to read/write output directory files? I should use single-file method right?

@vitek-karas
Copy link
Member

I don't know what you mean...

Self-contained in .NET Core SDK refers to applications which carry the .NET Core framework with them - they don't require .NET Core preinstalled on the machine to run. This typically makes them large (~70MB or more). Making application self-contained should not in any way affect where/how additional files are packaged with the application.

Single-file applications are packaged into much fewer files (ideally just one). Single-file can be combined with self-contained. On Windows due to some limitations typical HelloWorld self-contained single-file application will have one large application.exe and several smaller native .dll files next to it (for example coreclr.dll).

In .NET 5 single-file application run directly from the .exe without writing anything to disk on startup. So if your application wants to carry additional data files with it, it can do it in multiple ways:

  • Put them next to the ,exe (this is the default behavior of the SDK) - in this case such files should behave almost exactly like in non-single-file applications. The only difference is that when the application is looking for them it should use AppContext.BaseDirectory to determine their location (specifically Assembly.Location will NOT work).
  • Put them as embedded resources into a managed assembly. In this case there's no file on disk (and so less files to make up an application). The downside is that there's no file, so if the application needs to use that asset as a real file it would have to copy it somewhere at runtime.

It's hard for me to guess what exactly your application is doing, specifically:

  • How is it including the data file in the project file?
  • How is it trying to access that file at runtime (how does it determine its location)?

@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Oct 5, 2020
@agocke agocke added this to the Future milestone Oct 5, 2020
@vitek-karas
Copy link
Member

Closing for now as there's no enough information. Please feel free to reopen is this is still a problem or you have additional questions.

@eiriktsarpalis eiriktsarpalis added question Answer questions and provide assistance, not an issue with source code or documentation. and removed customer assistance labels Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Single-File question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
Status: No status
Development

No branches or pull requests

5 participants