Could not load file or assembly 'MaterialDesignColors, Culture=neutral' or one of its dependencies
Hi am getting the following error when running my class library project.
"Could not load file or assembly 'MaterialDesignColors, Culture=neutral' or one of its dependencies. The system cannot find the file specified.":"MaterialDesignColors, Culture=neutral"} System.Exception {System.IO.FileNotFoundException
I tried the below link forthe issue Could not load file or assembly 'MaterialDesignThemes.Wpf and the issue got fixed by adding the piece of code suggested as below .
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
ShadowAssist.SetShadowDepth(this, ShadowDepth.Depth0);
}
}
Is there any fix like above available for `MaterialDesignColors.dll ?
Note : All the dlls exists in same folder.
it would be interesting which dependency you could not load. Can you specify more detailed information. You can catch a ReflectionTypeLoadException. There is a Types property, which lists all types they could not be loaded.
I have added MaterialDesignColors.dll and used in my application .But when running getting an error as Could not load file MaterialDesignColors.dll
@Arshad8464 take a look at Fuselofvw for debugging assembly resolution errors (example of using it here). There are many reasons why this error could occur. The most common is a version mismatch from the version of MaterialDesignColors.dll that your app was compiled against and the one sitting in the directory. The other time this occurs is when this library is used as part of an extension for some other application.
Hi! I am interested if you can elaborate on this statement "The other time this occurs is when this library is used as part of an extension for some other application." I am trying to use MaterialDesignThemes in a class library. I am able to reference it correctly, but I get the same error as the original poster. Thank you.
I figured my problem out and I am ashamed to admit how simple the solution was - I simply wasn't copying the referenced .dll(s) to the location where the assembly is during run time. Once I fixed that it was perfect. Thank you.
I use with prism in the following way:
My shell has the nuget reference to material design xaml library and in the app.xaml I set it up.
My modules also have nuget reference to material design xaml lib. As you know, UI modules are wpf usercontrols, so in each page I include the material design xaml as resource. This allows me to see styles in design time.
When I deploy my modules everything is loaded correctly.
There's no duplicate resources because I use a specialized resource class to load resources only in design time in my modules.
On Sun, Jul 15, 2018, 19:56 Deyan Nenov [email protected] wrote:
Hi! I am interested if you can elaborate on this statement "The other time this occurs is when this library is used as part of an extension for some other application." I am trying to use MaterialDesignThemes in a class library. I am able to reference it correctly, but I get the same error as the original poster. Thank you.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/issues/980#issuecomment-405110585, or mute the thread https://github.com/notifications/unsubscribe-auth/AH_-jzI9Abbw4jVoW453QgHYqKpxdApxks5uG5BMgaJpZM4VHIlR .
I had the same error. I used the shadow assist code above for the 'MD Themes' and used the code below to get the 'Colors'.
var hue = new Hue("Dummy", Colors.AliceBlue, Colors.AntiqueWhite);
Is there a solution to this problem? I get a very similar error: `System.Windows.Markup.XamlParseException: ''Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
FileNotFoundException: Could not load file or assembly 'MaterialDesignThemes.Wpf, Culture=neutral' or one of its dependencies`. I am developing a class library. I created a resource dictionary file with the following content:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
And i use it on my initial page in a following way:
<Page.Resources>
<ResourceDictionary Source="/MyAsembly;component/ResourceDictionary/MaterialDesign.xaml" />
</Page.Resources>
Unfortunately, i do not have admin privileges on the computer where i'm developing code, so i cannot run Fuselofvw as suggested in one of the previous posts.
@JovanovicMarija there is not really a single solution. As the error indicates the issue is the running process is unable to locate the assembly. Can you provide more detail on what type of app this is, how your projects reference each other, and which ones are referencing the material design library.
The problem might be Revit and the way it's loading dlls. I introduced the following code
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; and
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("MaterialDesignTheme"))
{
string filename = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
filename = Path.Combine(filename, "MaterialDesignTheme.Wpf.dll");
if (File.Exists(filename))
{
return Assembly.LoadFrom(filename);
}
}
return null;
}
But now i get the error:
System.Windows.Markup.XamlParseException: ''Set property 'System.Windows.ResourceDictionary.Source' threw an exception.'
FileNotFoundException: Could not find file 'MaterialDesignTheme.Wpf.resources'.
I have found this github issue that faces the same problem, but his app runs and my app chrashes.
@JovanovicMarija ah so this is being loaded as part of an extension. Dynamic assembly loading can be quite tricky. The code you have above is only attempting to load the MaterialDesignTheme.Wpf.dll but it is ignoring the MaterialDesignColors.dll which you will need to load as well.
@Keboo i apologise for my late response. My second post was only one of many quick&dirty ways i tried in order to solve the problem, i should have posted the code that covers loading MatreialDesignColors as well (yet the error message would have been the same). What solved my problem was completely abendoning the code snipped from my second post and doing what @Arshad8464 and @z3ke1r did. I didn't originally understand that this approach would solve the problem, because i was trying to follow MVVM pattern and keep code behind clean. Therefore it didn't make any sense to me that they were suggesting to put bullshit code in the file that i was trying to keep empty. But hey, it works now! :)
Closing for now as all of the issues appear to be outside of this library. Let me know if there is more that needs to be addressed here.
For folks still encountering this issue: this post by Carlos Anderson explains what's going on:
There’s another tricky thing. Because you don’t use any classes in the Material Design assemblies, your script assembly doesn’t load those assemblies. It’s the XAML parser that uses the Material Design assemblies and therefore tries to load them. The problem is that, because it’s not your assembly that loads them, .NET looks for the Material Design assemblies in the wrong place.
And provides a solution similar to what @z3ke1r suggests:
public MainWindow()
{
InitializeMaterialDesign();
InitializeComponent();
}
private void InitializeMaterialDesign()
{
// Create dummy objects to force the MaterialDesign assemblies to be loaded
// from this assembly, which causes the MaterialDesign assemblies to be searched
// relative to this assembly's path. Otherwise, the MaterialDesign assemblies
// are searched relative to Eclipse's path, so they're not found.
var card = new Card();
var hue = new Hue("Dummy", Colors.Black, Colors.White);
}
This solved it for me.
@mswaidan does that also work in release builds? I'm using some code at work that also requires me to reference the Colors dll and do a noop call because a method like yours gets optimized away.
@jespersh Just checked, and that solution works on my project's release build. This is definitely at the edges of my understanding though, so can't say whether it will work in other cases.
Found it again. If @mswaidan's suggestion doesn't work, try this (from https://stackoverflow.com/a/39755840):
Action<Type> noop = _ => {};
var dummy = typeof(Card);
noop(dummy);
You'd need the same for the Color dll (Hue for example)
Hi. I tried everything from this discussion... And finally i still getting an error.

The only solution i found is to put MaterialDesign libraries into Revit app folder. (C:\Program Files\Autodesk\Revit 2017). I tried to load these libraries at runtime with but still got same exception. Does anybody knows any better solution?
Finally found solution.
May be this gonna help someone. Here is it:
public class AssemblyLoader: IDisposable {
private static string ExecutingPath => Assembly.GetExecutingAssembly().Location;
public AssemblyLoader() {
AppDomain.CurrentDomain.AssemblyResolve += LoadMaterialDesign;
}
private static Assembly LoadMaterialDesign(object sender, ResolveEventArgs args) {
if (null == ExecutingPath) return null;
string assemlyToLoad = string.Empty;
string GetAssemblyName(string fullName) => fullName.Substring(0, fullName.IndexOf(','));
var path = ExecutingPath;
var dir = new FileInfo(path).Directory;
var assemblies = from file in dir.EnumerateFiles()
where file.Name.EndsWith(".dll") ||
file.Name.EndsWith(".exe")
select Assembly.LoadFrom(file.FullName);
foreach(var assembly in assemblies) {
var assemName = GetAssemblyName(assembly.FullName);
var requested = GetAssemblyName(args.Name);
try {
if (assemName == requested) {
return assembly;
}
} catch (Exception) {
continue;
}
//}
}
return null;
}
void IDisposable.Dispose() {
AppDomain.CurrentDomain.AssemblyResolve -= LoadMaterialDesign;
}
}
Usage example:
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
using var loader = new AssemblyLoader();
/// Your command implementation
return Result.Succeeded();
}
}
@hedinjke could you also make it a gist?
@jespersh yes, of cause. If i understood you right... Here is it. I'm sorry, but i'm new in C#, Git and english skills... So if u help me to improve anything here would be awesome :)