0

I'm starting to look at adding localisation my plug-in (For Revit if that's relevant), using WPFLocalizeExtension.

I've used nuget to add WPFLocalizeExtension to my project, and everything compiles fine and shows up in designer.

So far, I've only used it for one of my windows, a small dialog. The plug-in loads fine, but when I init/show this dialog it throws this exception:

System.Windows.Markup.XamlParseException: 'Could not load file or assembly 'WPFLocalizeExtension, PublicKeyToken=c726e0262981a1eb' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)'

The reference is set to copy local

enter image description here

The debug directory has a copy of the assembly WPFLocalizeExtension.dll.

Any ideas why this is throwing up this exception?

Cheers

2

2 Answers 2

0

Check if all package dependencies are pulled in:
enter image description here

Also try to explicitly add all these dependencies to the application assembly (the one that generates the executable file, for example, *.exe).

Sign up to request clarification or add additional context in comments.

2 Comments

Good shout, I checked that and they're in there. I have a theory that I'm not sure how to test for. The main application, Revit, opens all these xml .addin files to load the plugins. Each .addin has an entry for the location of the .dll file to load. I'm wondering if it's not using the location of the plug-in .dll to find and load in referenced assemblies, just the location of revit.exe. Is there a way within a class library to specify a directory to look for dependencies at load time?
@whitelined It matters how the URIs of the sources are specified. If the required XAML files are compiled into an assembly, then the URI must be in the full format of the packed resource.
0

After a bit of research and some trial and error, I've come up with the answer.

The main application, revit.exe, loads each addin/plugin from an .addin/.xml file in a folder. Here's an example of a typical .adding xml file it will load:

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Application">
    <Name>BDS</Name>
                <Assembly>D:\dev2\BerkshireDesignServices\bin\Debug\BerkshireDesignServices.dll</Assembly>
    <AddInId>98f0af1f-a857-44e0-8b7a-cb52f24f7543</AddInId>
    <FullClassName>BDS.BDS</FullClassName>
    <VendorId>AJPH</VendorId>
    <VendorDescription>AJPH</VendorDescription>
  </AddIn>
</RevitAddIns>

When revit.exe runs, it loads each .dll from the path specified in the "Assembly" xml tag.

This is typically fine for any application that doesn't use an external library not in .NET framework (.NET core for Revit 2025+). When any plug-in/adding has an additional class library to include, the main application will only search for these additional libraries where the execution has started. So, to resolve this problem in a class library you add a handler at the beginning of the library initialization code, like so:

private void AddLibraryHandler(
{
    AppDomain.CurrentDomain.AssemblyResolve += (sender, args)=>{
    foreach(var e in libariesToLoad)
        {
            if (args.Name.Contains(e)
            {
                return Assembly.LoadFrom(Path.Combine(libPath, $"{e}.dll"));
            }
        }
        return null;
        };
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.