Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PeerLoadingObjectHolder"/> class.
        /// </summary>
        public PeerLoadingObjectHolder(BinaryReader reader)
        {
            Debug.Assert(reader != null);

            var originNodeId = reader.ReadGuid().GetValueOrDefault();

            var typeName = reader.ReadString();

            var ignite = reader.Marshaller.Ignite;

            using (new PeerAssemblyResolver(ignite, originNodeId))  // Resolve transitive dependencies when needed.
            {
                // Resolve type from existing assemblies or from remote nodes.
                var type = Type.GetType(typeName, false)
                           ?? PeerAssemblyResolver.LoadAssemblyAndGetType(typeName, ignite, originNodeId);

                Debug.Assert(type != null);

                _object = reader.Deserialize <object>(type);
            }
        }
Ejemplo 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
            {
                using (PeerAssemblyResolver.Disable())
                {
                    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);
        }