Exemplo n.º 1
0
 /// <summary>
 /// Gets the assembly.
 /// </summary>
 private static Assembly GetAssembly(IIgniteInternal ignite, string assemblyName, Guid originNodeId)
 {
     return(LoadedAssembliesResolver.Instance.GetAssembly(assemblyName)
            ?? AssemblyLoader.GetAssembly(assemblyName)
            ?? LoadAssembly(ignite, assemblyName, originNodeId));
 }
Exemplo n.º 2
0
        /** <inheritdoc /> */
        public AssemblyRequestResult Invoke(AssemblyRequest arg)
        {
            if (arg == null)
            {
                throw new IgniteException("GetAssemblyFunc does not allow null arguments.");
            }

            if (arg.AssemblyName == null)
            {
                throw new IgniteException("GetAssemblyFunc does not allow null AssemblyName.");
            }

            Debug.WriteLine("Peer assembly request: " + arg.AssemblyName);

            // Try assemblies in main context.
            var asm = LoadedAssembliesResolver.Instance.GetAssembly(arg.AssemblyName);

            if (asm != null)
            {
                if (asm.IsDynamic)
                {
                    return(new AssemblyRequestResult(null,
                                                     "Peer assembly loading does not support dynamic assemblies: " + asm));
                }

                return(new AssemblyRequestResult(AssemblyLoader.GetAssemblyBytes(asm), null));
            }

            // Try cached assemblies.
            var bytes = AssemblyLoader.GetAssemblyBytes(arg.AssemblyName);

            if (bytes != null)
            {
                return(new AssemblyRequestResult(bytes, null));
            }

            // Assembly may be present but not loaded - attempt to load into main context.
            try
            {
                asm = Assembly.Load(arg.AssemblyName);

                if (asm != null)
                {
                    return(new AssemblyRequestResult(AssemblyLoader.GetAssemblyBytes(asm), null));
                }
            }
            catch (FileNotFoundException)
            {
                return(null);
            }
            catch (FileLoadException ex)
            {
                return(new AssemblyRequestResult(null, string.Format("Failed to load assembly: {0} ({1})", asm, ex)));
            }

            catch (BadImageFormatException ex)
            {
                return(new AssemblyRequestResult(null, string.Format("Failed to load assembly: {0} ({1})", asm, ex)));
            }

            return(null);
        }