benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.71k stars 143 forks source link

Adonis.Window Crashes on startup if not launched from the base directory #63

Closed Swiftpaws closed 4 years ago

Swiftpaws commented 4 years ago

Describe the bug If the application uses the AdonisWindow and is launched with anything but the base directory (where the .dll files are located) as the "Start in" location it will crash at: AdonisUI.Controls.AdonisWindow.GetApplicationIcon()

To Reproduce Steps to reproduce the behavior:

  1. Create App which uses the AdonisWindow (.net core 3.1)
  2. Add an icon via the project properties
  3. Compile
  4. Try to launch it via cmd from the downloads folder (cmd current dir is downloads and start it with an absolute path)

Expected behavior No crash

Screenshots

Additional context The icon visibility in the adonis window does not affect this behaviour

Exception + StackTrace

System.Windows.Markup.XamlParseException: 'The invocation of the constructor on type 'Okami.Views.MainWindow' that matches the specified binding constraints threw an exception.'

FileNotFoundException: Could not load file or assembly 'C:\Users\pub\Downloads\Okami.dll'. The system cannot find the file specified.

This exception was originally thrown at this call stack: System.Drawing.Icon.ExtractAssociatedIcon(string, int) System.Drawing.Icon.ExtractAssociatedIcon(string) AdonisUI.Controls.AdonisWindow.GetApplicationIcon() AdonisUI.Controls.AdonisWindow.AdonisWindow() Okami.Views.MainWindow.MainWindow()

benruehl commented 4 years ago

FileNotFoundException: Could not load file or assembly 'C:\Users\pub\Downloads\Okami.dll'. The system cannot find the file specified.

This part surprises me. AdonisWindow looks for the icon in Assembly.GetEntryAssembly() which seems to return 'C:\Users\pub\Downloads\Okami.dll' for you. I would expect the entry to be an .exe file.

What does your application structure look like? Does your application only constist of this Okami.dll? Is there an additional .exe assembly involved? How do they relate? Did you start your app via unmanaged code?

Swiftpaws commented 4 years ago

Implementing AdonisWindow

\AdonisWindowIcon_Bug\Demo\Demo> .\bin\Debug\netcoreapp3.1\Demo.exe -> Does not start

AdonisWindowIcon_Bug\Demo\Demo\bin\Debug\netcoreapp3.1> .\Demo.exe -> Works

Implementing only Window

-> Both work

I have created a test app here -> https://github.com/Swiftpaws/AdonisWindowIcon_Bug

benruehl commented 4 years ago

Could you please explain what you mean with > . in you paths? I downloaded your demo and for me it runs perfectly. But I am not sure what the difference in those two paths is that you mentioned.

Swiftpaws commented 4 years ago

They are command line calls

image

The first command does not work while the second one does. The difference is the current directory - if the current directory (of the command line) is the same as the .exe it can launch if that is not the case it will not launch

benruehl commented 4 years ago

Oh now I see. Sorry it took me so long to understand what you meant. I am now able to reproduce the issue and working on a fix.

benruehl commented 4 years ago

I created a PR which solves the issue. At least it works for your demo project. Before merging you can check if it works for your original project as well if you want.