I’ve been working on converting some of my PowerShell scripts for SCCM into Graphical User Interfaces (GUIs), specifically using Windows Presentation Foundation (WPF). I’ve been a long admirer of the ConfigMgr OSD Front End from scconfigmgr.com by Nickolaj Andersen who pointed me to the MahApps.Metro theme when I complimented him on the aesthetics of his Front End.
Now, coming back to this post. Getting the MahApps.Metro theme to work with the WPF GUI requires loading a couple of DLL files in the PowerShell script but annoyingly I ran into a problem where the DLLs wouldn’t import in the SCCM/MDT boot images In WindowsPE but works flawlessly in Windows 10. This is the error message I was getting:
“Could not load file or assembly MahApps.Metro.dll or one of its dependencies. Operation is not supported.”
Attempting to load “System.Windows.interactivity.dll” also threw the same error message. I also tried changing the DLL files from .Net 4.0 to 4.5 and also tried solutions from the community which presented me with the same error message each time. I knew these community solutions work in other environment so there was something definitely wrong from my end.
After trying a lot of different things I finally managed to resolve this with a workaround. Here’s what I done.
First, let’s take a look at the three DLLs I’ve been trying to load in my script.
[System.Reflection.Assembly]::LoadWithPartialName("presentationframework") [System.Reflection.Assembly]::LoadFrom("$MyScriptDir\assembly\MahApps.Metro.dll") [System.Reflection.Assembly]::LoadFrom("$MyScriptDir\assembly\System.Windows.Interactivity.dll")
The first DLL, the “presentationframework.dll”, imported successfully whereas the other two failed consistently no matter what I tried. After concentrating far too long on the two problematic DLLs and failing to come up with a solution I decided to take a closer look at the “presentationframework.dll”. When I load this DLL I get the following output in my console:
I saw that the DLL was being loaded from “X:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\presentationframework\v4.0_126.96.36.199__31bf3856ad364e35”.
So I decided to manually create this folder structure as shown below for each of my DLL files and copy them over:
Folder structure to create and location to copy MahApps.Metro.dll:
Folder structure to create and location to copy System.Windows.Interactivity.dll:
I then tried loading the DLL files using the following lines:
And voila! The two DLL files were loaded successfully!
The GUI and the theme works absolutely fine with this workaround. I spent a lot of time grappling with this problem so it was a relief to finally have it resolved, not to mention my GUI looks so much better with the theme. I just had to write this post not only for my own reference but also hoping it may help someone else out there too.
I’m refraining myself from inserting a screenshot of the GUI as I want to write a separate post introducing it to the community :)