protected override Assembly Load(AssemblyName assemblyName)
        {
            // CONSIDER: Should we consider priorities for packed vs local files?

            // First try the regular load path
            string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);

            if (assemblyPath != null)
            {
                return(LoadFromAssemblyPath(assemblyPath));
            }

            // Finally we try the AssemblyManager
            return(AssemblyManager.AssemblyResolve(assemblyName));
        }
示例#2
0
        public static short Initialize(void* xlAddInExportInfoAddress, void* hModuleXll, void* pPathXLL)
        {
            string pathXll = Marshal.PtrToStringUni((IntPtr)pPathXLL);
            _alc = new ExcelDnaAssemblyLoadContext(pathXll);
            AssemblyManager.Initialize((IntPtr)hModuleXll, pathXll, _alc);
            var loaderAssembly = _alc.LoadFromAssemblyName(new AssemblyName("ExcelDna.Loader"));
            var xlAddInType = loaderAssembly.GetType("ExcelDna.Loader.XlAddIn");
            var initOK = (bool)xlAddInType.InvokeMember("Initialize", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null,
                new object[] { (IntPtr)xlAddInExportInfoAddress, (IntPtr)hModuleXll, pathXll,
                    (Func<string, int, byte[]>)AssemblyManager.GetResourceBytes,
                    (Func<string, Assembly>)_alc.LoadFromAssemblyPath,
                    (Func<byte[], byte[], Assembly>)_alc.LoadFromAssemblyBytes,
                    (Action<TraceSource>)Logger.SetIntegrationTraceSource });

            return initOK ? (short)1 : (short)0;
            }
示例#3
0
 public static bool Initialize64(long xlAddInExportInfoAddress, long hModuleXll, string pathXll)
 {
     // NOTE: The sequence here is important - we install the AssemblyManage which can resolve packed assemblies
     //       before calling LoadIntegration, which will be the first time we try to resolve ExcelDna.Integration
     AssemblyManager.Initialize((IntPtr)hModuleXll, pathXll);
     AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) => AssemblyManager.AssemblyResolve(new AssemblyName(args.Name));
     return XlAddInInitialize((IntPtr)xlAddInExportInfoAddress, (IntPtr)hModuleXll, pathXll, AssemblyManager.GetResourceBytes, AssemblyManager.LoadFromAssemblyPath, AssemblyManager.LoadFromAssemblyBytes, Logger.SetIntegrationTraceSource);
 }