Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
185
Loading IG assemblies dynamically
posted

Hi,

We are using IG controls (Win 8.1)..

We have a Utility tool which is using the IG controls.. but as it is to be a standalone appplication (Win form application)we are not suppose put dlls along with the exe or put them in the GAC.. so thought of loading the IG contols dynamically when the Assembly resolve failed...

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

But, the event is not getting fired and application fails with error

Could not load file or assembly 'Infragistics2.Win.v8.1, Version=8.1.20081.2013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb' or one of its dependencies. The system cannot find the file specified.

Can we load IG asseblies dynamically or not?

Thanks

Ranganatha

Parents
No Data
Reply
  • 821
    Offline posted

    Just to give you an idea;

     

        public class AssemblyLoader
        {
            private static readonly Dictionary<string, Assembly> cachedAssemblies = new Dictionary<string, Assembly>();
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
            static AssemblyLoader()
            {
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_OnAssemblyResolve;
               
            }
            /// <summary>
            /// This method is used to initialize this type through the static constructor for assemblyresolve event handling.
            /// DO NOT REMOVE THIS METHOD, OR THE CALL TO IT!
            /// </summary>
            public static void Initialize()
            {
            }

            public static Assembly CurrentDomain_OnAssemblyResolve(object sender, ResolveEventArgs args)
            {
                try
                {
                    string assemblyName = args.Name;
                    assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(","));
                    return LoadAssembly(assemblyName);
                    return null;

                }
                catch (Exception ex)
                {
                    Console.WriteLine("converter: " + ex.Message);
                    return null;
                }
            }
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFile"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom")]
            private static Assembly LoadAssembly(string assemblyName)
            {
                Assembly assembly;
                if (!cachedAssemblies.TryGetValue(assemblyName, out assembly))
                {
                    /*Load infragistics assemblies from where you put them in */
                   
                }
                return assembly;
            }
        }

Children
No Data