ExcelDNA with WPF/MaterialDesignInXAML

247 views
Skip to first unread message

A Parmar

unread,
Mar 7, 2024, 3:46:17 PM3/7/24
to Excel-DNA
Hi Govert/Team,

ExcelDNA Version (latest): 1.8.0-alpha2
Target: NET 6.0-Windows

I'm trying to use ExcelDNA to launch WPF Project (this works), but when I reference another library in WPF (MaterialDesignInXAML) I have an exception thrown:
System.Windows.Markup.XamlParseException:'Could not load file or assembly 'MaterialDesignThemes.Wpf

I can I also start the WPF Project with the MaterialDesign directly without any issues.

Any ideas on this one?

Govert van Drimmelen

unread,
Mar 8, 2024, 12:10:45 PM3/8/24
to Excel-DNA
Are you seeing this while debugging, or when running the packed add-in?

Could you perhaps make a small project that shows how to reproduce the problem?

-Govert

A Parmar

unread,
Mar 8, 2024, 2:02:52 PM3/8/24
to Excel-DNA
Hi Govert,

when I posted the message it was while debugging - but I've tried directly using the "...64.xll" file and that also fails.

I've made a very small project below:


Thanks

Govert van Drimmelen

unread,
Mar 8, 2024, 2:19:00 PM3/8/24
to exce...@googlegroups.com

OK great – I’ll have a look.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/743e5e56-e6f6-4b4f-a65d-eedff13cb806n%40googlegroups.com.

Govert van Drimmelen

unread,
Mar 18, 2024, 6:35:59 AM3/18/24
to Excel-DNA
I've had a look at your project and get the same error.
I don't know what the mechanism is whereby .NET and WPF looks for and loads the extra assemblies like MaterialDesign.Wpf in this case.
I suppose there is some special load and search mechanism that does not go through the standard .NET assembly load paths.

However, you can pre-load the assembly into the right context by calling some code that uses the relevant types as soon as your add-in loads.
For example, you can add a class that implements IExcelAddIn, and use the AutoOpen to iniatilize the assemblies you need.
Then when you later make the WPF calls, the assemblies are already loaded and work fine.
I put some suggested code below.

-Govert

using System.Windows.Media;
using ExcelDna.Integration;
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;

namespace ExcelDNATest
{
    public class AddIn : IExcelAddIn
    {
        public void AutoOpen()
        {
            InitializeMaterialDesign();
        }

        public void AutoClose()
        {
        }

        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 or loaded from the packed add-in.
            var card = new Card();
            var hue = new Hue("Dummy", Colors.Black, Colors.White);
        }
    }
}

梁理

unread,
Mar 18, 2024, 10:20:46 AM3/18/24
to Excel-DNA
请问能用类似的方法加载HandyControl吗?使得可以在excel插件中使用HandyControl的窗体、Growl等。如果可行的话,麻烦给出一个简单的示例。
谢谢!

Sorry, I don't speak English. The following is translated using Baidu:
Can you use a similar method to load HandyControl? Enable the use of HandyControl forms, Growl, etc. in Excel plugins. If feasible, please provide a simple example.
Thank you!

A Parmar

unread,
Mar 19, 2024, 6:20:05 AM3/19/24
to Excel-DNA
Thank you Govert! 
That works - I was trying to avoid pre-loading, as thought there could be a better way - looks like this is the best way.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages