MahApps / MahApps.Metro.IconPacks

Awesome icon packs for WPF and UWP in one library
MIT License
1.76k stars 215 forks source link

VS2022 can't find IconPacks resource #307

Closed dknippel closed 1 year ago

dknippel commented 1 year ago

I've installed 4.11.0 via the NuGet Package Manager within VS2022. However, when I run my app, it fails on InitializeComponent() and states:

Could not load file or assembly 'MahApps.Metro.IconPacks.Modern blah blah blah'

At design time, the XAML designer appears to be able to find the resource like so: (see first screen scrape)

XAML_desgin_time

But when I run the app, it doesn't seem to find it like so: (see second screen scrape)

XAML_parse_error

Do I need to explicitly add a ResourceDictionary to my App.xaml perhaps like so:

                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />

                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro.IconPacks;component/Styles/Icons.xaml" />

When I try to add said ResourceDictionary it complains with:

Cannot locate resource 'icons.xaml'

Everything worked great with the MahApps.Metro stuff, but not so much with the IconPacks stuff. What am I missing?

dknippel commented 1 year ago

Hi @punker76 , is there anyway you could provide some help with this?

It appears to have several dependencies such as .NET Core 3.1, .NET 4.5, etc. However, I only need it for .NET 4.7.2. My IDE is VS2022, and my OS is Windows 11 Pro

Generally, the NuGet Manager seems to install dependencies correctly but I still seem to be missing something? Am I missing something? Again, what's weird is the IconPacks seems to work fine in design mode, but not runtime.

I've also tried to build from source via https://github.com/MahApps/MahApps.Metro.IconPacks/releases/tag/4.11.0 but that is another nightmare that appears to have even more dependencies. Any advice you could provide would be great! :-)

UPDATE

OK, I've been able to modify the https://github.com/MahApps/MahApps.Metro.IconPacks/releases/tag/4.11.0 solution so that it only builds:

Interestingly enough, to get it to build successfully, one has to edit the global.json file to specify the latest SDK available on their dev box. Is this by design, and if it is, why are there zero support docs to explain any of this?

Regardless, after replacing the references added by NuGet with the above https://github.com/MahApps/MahApps.Metro.IconPacks/releases/tag/4.11.0 assemblies .... still no joy at runtime -->

Could not load file or assembly 'MahApps.Metro.IconPacks.Modern, PublicKeyToken=0c0d510f9915137a' or one of its dependencies. The system cannot find the file specified.

Any thoughts? I'm open to enlightenment... :-|

UPDATE - PART DEUX

OK, I discovered why none of the MahApps.Metro.IconPacks resources were being found at runtime. Because they weren't being copied to the output directory at build time and yes, I had the compile option of Copy Local set to True. Strange though...

Any ideas on why the IconPacks assembly reference is not getting copied?

punker76 commented 1 year ago

@dknippel This sounds all very strange, because I never seen such errors.

punker76 commented 1 year ago

@dknippel And it's not necessary to add any resource at App.xaml from IconPacks, except you want to override some styles.

punker76 commented 1 year ago

@dknippel Here is my short/simple sample created with the latest VS 2022 update.

WpfAppIconPacks2.zip

image

dknippel commented 1 year ago

Hi @punker76 , thanks for your reply. Yes, your WpfAppIconPacks2.zip sample works fine. It is a bit different setup than mine. Regardless, I am having to use the workaround described in UPDATE - PART DEUX above. Still strange why none of the MahApps.Metro.IconPacks assembly references get copied to the output directly. Oh well :-|

punker76 commented 1 year ago

@dknippel If it’s possible then send me your app, cause I’m interested in the different setup.

dknippel commented 1 year ago

I'm not sure if I can legally send you the app (government medical imaging technology). However, it basically goes like this:

All .NET 4.7.2 components...

Host (console app)

So, life begins something like this:

  1. The Host spins up an instance of the DRACO Engine Manager
  2. If that succeeds, the Host then spins up the DRACO GUI and passes in said engine manager
  3. the engine manager and the GUI interact accordingly until the user terminates the application session

Obviously the DRACO GUI contains a reference to (via NuGet Manager):

And as one would expect in the Host output directory:

However, what is not expected:

kiranshahi commented 1 year ago

Hi @dknippel have you solved this issue?

dknippel commented 1 year ago

Kind of I guess. I mean, the workaround is:

I have to explicitly add (via NuGet Manager) the MahApps.Metro.IconPacks package to Host