question

jalza avatar image
0 Votes"
jalza asked Viorel-1 commented

Run WPF application (.NET 5) outside Visual Studio

I developed a desktop application using WPF and .NET 5. If I run it from Visual Studio 2019, everything works without problems.

My app uses a library to manage video cameras (it is added as an Assembly) and 3 nuget packages (MvvmLightStd10, Newtonsoft.Json and System.Drawing.Common).

Now I need to deploy the application on another computer as an .exe file. I follow these steps:

  • Right click on project.

  • Select Publish.

  • Folder > Next > Folder.

  • I set the location I want to use.

  • Click on Finish button.

  • Click on Show all settings in the new profile

I chose this configuration:

138584-publish-profile.png

After publish, I get the .exe file, it's .pdb file and library's (video cameras) .xml file in the specified folder.

If I double click on .exe file the application runs, but the window is not displayed. I know the application runs because I create a default setting JSON file at start, and it is created.

There is no error messages, so I don't know what is happening. Do you have any idea?

dotnet-csharpdotnet-runtime
publish-profile.png (10.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Do you think that it is terminated (i.e. it is not displayed by Task Manager)?


0 Votes 0 ·

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered jalza commented

Consider Application.DispatcherUnhandledException Event and write to a log file. If you need an idea on how to log see my repo.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for answer @karenpayneoregon this is my App.xaml.cs file:

 public partial class App : Application
 {
     public static Settings Settings { get; set; }

     public App()
     {
         this.DispatcherUnhandledException += this.App_DispatcherUnhandledException;
         try
         {
             App.Settings = new Settings();
             App.Settings.Load(); // this creates default settings.json file if does not exist
         }
         catch (Exception exception)
         {
             this.SaveException(exception);
             App.Current.Shutdown();
         }
     }

     private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
     {
         this.SaveException(e.Exception);
     }

     private void SaveException(Exception exception)
     {
         string text = $"{exception.Message}{Environment.NewLine}{exception.StackTrace}";
         File.WriteAllText("error.txt", text);
     }
 }

No error.txt file is written.

0 Votes 0 ·