Skip to main content
All docs
V24.1

BindToTypePolicy.QueryAssemblyLoad Event

Allows you to spot an “unknown” assembly before it is loaded, check its name, and allow or cancel the operation.

Namespace: DevExpress.Utils

Assembly: DevExpress.Data.v24.1.dll

NuGet Package: DevExpress.Data

Declaration

public static event BindToTypePolicy.WeakEventHandler<BindToTypePolicy.QueryAssemblyLoadEventArgs> QueryAssemblyLoad

Event Data

The QueryAssemblyLoad event's data class is BindToTypePolicy.QueryAssemblyLoadEventArgs. The following properties provide information specific to this event:

Property Description
Assembly Gets or sets the assembly.
AssemblyName Gets the assembly name. Inherited from BindToTypePolicy.BindToTypeBaseQueryArgs.
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
IsKnownType Gets whether the type is whitelisted (the type is safe). Inherited from BindToTypePolicy.BindToTypeBaseQueryArgs.
LoadLevel This member supports the internal infrastructure and is not intended to be used directly from your code.
QueryLevel This member supports the internal infrastructure and is not intended to be used directly from your code. Inherited from BindToTypePolicy.BindToTypeBaseQueryArgs.

The event data class exposes the following methods:

Method Description
ToString() Returns a string in the following format: Load Level: {LoadLevel}, Requested Assembly: {AssemblyName}.

Remarks

The BindToTypePolicy raises the QueryAssemblyLoad event when DevExpress UI controls load assemblies. Handle this event to spot an “unknown” assembly before it is loaded, check its name, and allow or cancel the operation.

Use the e.AssemblyName parameter to obtain the assembly name. Set the e.Cancel parameter to true to cancel the operation.

The following example loads a specific version from multiple versions of an assembly:

using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace DXApplication {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.Utils.BindToTypePolicy.QueryAssemblyLoad += BindToTypePolicy_QueryAssemblyLoad;
            Application.Run(new Form1());
        }
        private static void BindToTypePolicy_QueryAssemblyLoad(object sender, DevExpress.Utils.BindToTypePolicy.QueryAssemblyLoadEventArgs e) {
            if (e.AssemblyName.StartsWith("EntityFramework", StringComparison.OrdinalIgnoreCase)) {
                // Loads a specific assembly version distributed with the application.
                var appDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                string path = Path.Combine(appDirectory, @"..\\Lib", "EntityFramework.dll");
                e.Assembly = Assembly.LoadFrom(path);
            }
        }
    }
}

Read the following topic for more information and examples: Safe Deserialization – How to Resolve Unknown Assembly Loads.

See Also