Skip to content
Flying Animal

Solving Load Assembly Issues In AEC Software

🕒 Published at:

Introduction

When you are developing a plugin for an AEC software, you may encounter a problem that your plugin cannot be loaded by the software. This article will show you how to solve this problem.

What is an Assembly?

Before diving into load assembly issues, it's important to understand what an assembly is. In C#, an assembly is a collection of types and resources that are built to work together as a logical unit. Assemblies can be either dynamically or statically linked.

Common Causes of Load Assembly Issues

  • Version Mismatch: One of the most common causes of load assembly issues is version mismatch. This occurs when the version of an assembly that your application depends on does not match the version that is installed on the system. This can cause the application to fail or produce unexpected results.
  • Missing Dependencies: Another common cause of load assembly issues is missing dependencies. An assembly may depend on other assemblies or libraries to function properly. If these dependencies are missing, the application may fail to load the assembly or produce unexpected results.
  • File Not Found: If the assembly file cannot be found, the application will fail to load the assembly. This can occur if the file has been moved or deleted, or if the application is looking in the wrong directory.
  • Security Restrictions: If the assembly is not signed or does not have the appropriate permissions, the application may fail to load the assembly. This can occur if the assembly is not trusted by the system.

How to Solve Load Assembly Issues

Check for Version Mismatch: To resolve version mismatch issues, you can use the Assembly Binding Log Viewer tool (Fuslogvw.exe) to diagnose the problem. This tool will provide detailed information about which assembly versions are being loaded and where they are being loaded from. You can also use the AssemblyVersion attribute in the assembly's metadata to specify a specific version.

Install Missing Dependencies: To resolve missing dependency issues, you can install the required dependencies on the system or include them with your application. You can also use the Assembly Binding Log Viewer tool to diagnose the problem and determine which dependencies are missing.

Check File Path: To resolve file not found issues, you can check the file path to ensure that the assembly is in the correct directory. You can also use the Assembly Binding Log Viewer tool to determine where the application is looking for the assembly.

Adjust Security Settings: To resolve security restriction issues, you can sign the assembly or give it the appropriate permissions. You can also use the Assembly Binding Log Viewer tool to diagnose the problem and determine which security settings are preventing the assembly from loading

Let's say you have an application that depends on a third-party assembly called "MyLibrary.dll". The application was built to work with version 1.0.0.0 of the assembly, but you have version 2.0.0.0 installed on your system. When you run the application, you get an error message saying that the assembly could not be loaded.

To resolve this issue, you can specify in your application's configuration file that it should use version 1.0.0.0 of "MyLibrary.dll". Here's how you can do that:

  1. Open your application's configuration file (App.config or Web.config, depending on whether you're building a desktop or web application).
  2. Add a <runtime> section inside the <configuration> section, if one doesn't already exist.
  3. Inside the <runtime> section, add an <assemblyBinding> section.
  4. Inside the <assemblyBinding> section, add a <dependentAssembly> element that specifies the name, public key token, and version of the assembly you want to bind to.
  5. Set the <bindingRedirect> element to specify the version of the assembly you want to use.

Here's an example of what the configuration file might look like:

xml
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MyLibrary" publicKeyToken="123456789abcdef" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

In this example, we're specifying that our application should use version 1.0.0.0 of "MyLibrary.dll" instead of any version between 0.0.0.0 and 2.0.0.0.

By adding this configuration to your application, you should be able to resolve the version mismatch issue and run your application successfully.

How To Solve Load Assembly Issues In AEC Software

Some of solutions are listed below:

  1. Check the version of the assembly that is installed on the system. If it is not the correct version, install the correct version.
  1. Check the bitness of the assembly. If it is not the correct bitness, install the correct bitness.
  1. Check the folder structure of the assembly. If it is not in the correct folder structure, move it to the correct folder structure.
  2. Check the name of the assembly. If it is not in the correct name, rename it to the correct name.
  1. Check the dependencies of the assembly. If it is missing dependencies, install the dependencies.
  1. Check the security settings of the assembly. If it is not signed or does not have the appropriate permissions, sign it or give it the appropriate permissions.

  2. Remove some Add-in from AEC Software, because some Add-in may be conflict with your assembly.

Use C# Code to Load Assembly when your add-in or application loading to software, this is a sample code:

cs

string assPath = Assembly.GetExecutingAssembly().Location;
string? dirPath = Path.GetDirectoryName(Path.GetFullPath(assPath)) ?? null;
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
    var assemblyName = new AssemblyName(args.Name);
    if (!string.IsNullOrEmpty(dirPath))
    {
        var assemblyPath = Path.Combine(dirPath, assemblyName.Name + ".dll");
        if (File.Exists(assemblyPath) == false) return null;
        var assembly = Assembly.LoadFrom(assemblyPath);
        return assembly;
    }
    return null;
};

Conclusion

Load assembly issues can be frustrating and time-consuming to resolve, but by following the tips outlined in this article, you should be able to diagnose and fix these issues quickly and effectively. By understanding the common causes of load assembly issues and knowing how to resolve them, you can save time and improve the performance of your applications.