コード例 #1
0
ファイル: 4objref.cs プロジェクト: wwkkww1983/ZJCredit
 private object GetCustomMarshaledCOMObject(object ret)
 {
     if (this.TypeInfo is DynamicTypeInfo)
     {
         IntPtr pUnk = IntPtr.Zero;
         if (this.IsFromThisProcess())
         {
             if (!this.IsFromThisAppDomain())
             {
                 try
                 {
                     bool fIsURTAggregated;
                     pUnk = ((__ComObject)ret).GetIUnknown(out fIsURTAggregated);
                     if (pUnk != IntPtr.Zero)
                     {
                         if (!fIsURTAggregated)
                         {
                             string typeName1    = this.TypeInfo.TypeName;
                             string name         = (string)null;
                             string assemblyName = (string)null;
                             // ISSUE: explicit reference operation
                             // ISSUE: variable of a reference type
                             string& typeName2 = @name;
                             // ISSUE: explicit reference operation
                             // ISSUE: variable of a reference type
                             string& assemName = @assemblyName;
                             System.Runtime.Remoting.TypeInfo.ParseTypeAndAssembly(typeName1, typeName2, assemName);
                             Assembly assembly = FormatterServices.LoadAssemblyFromStringNoThrow(assemblyName);
                             if (assembly == (Assembly)null)
                             {
                                 throw new RemotingException(Environment.GetResourceString("Serialization_AssemblyNotFound", (object)assemblyName));
                             }
                             Type t = assembly.GetType(name, false, false);
                             if (t != (Type)null && !t.IsVisible)
                             {
                                 t = (Type)null;
                             }
                             object objectForIunknown = Marshal.GetTypedObjectForIUnknown(pUnk, t);
                             if (objectForIunknown != null)
                             {
                                 ret = objectForIunknown;
                             }
                         }
                     }
                 }
                 finally
                 {
                     if (pUnk != IntPtr.Zero)
                     {
                         Marshal.Release(pUnk);
                     }
                 }
             }
         }
     }
     return(ret);
 }
コード例 #2
0
 internal Assembly GetAssembly()
 {
     if (_assembly == null)
     {
         _assembly = FormatterServices.LoadAssemblyFromStringNoThrow(_assemblyString);
         if (_assembly == null)
         {
             throw new SerializationException(SR.Format(SR.Serialization_AssemblyNotFound, _assemblyString));
         }
     }
     return(_assembly);
 }
コード例 #3
0
 internal Assembly GetAssembly()
 {
     if (this.assembly == null)
     {
         this.assembly = FormatterServices.LoadAssemblyFromStringNoThrow(this.assemblyString);
         if (this.assembly == null)
         {
             throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyNotFound", new object[] { this.assemblyString }));
         }
     }
     return(this.assembly);
 }
コード例 #4
0
 public Assembly GetAssembly()
 {
     if (_assembly == null)
     {
         _assembly = FormatterServices.LoadAssemblyFromStringNoThrow(AssemblyString);
         if (_assembly == null)
         {
             throw new SerializationException(RemotingResources.SerializationAssemblyNotFound.Format(AssemblyString));
         }
     }
     return(_assembly);
 }
コード例 #5
0
        private object GetCustomMarshaledCOMObject(object ret)
        {
            DynamicTypeInfo dynamicTypeInfo = this.TypeInfo as DynamicTypeInfo;

            if (dynamicTypeInfo != null)
            {
                IntPtr intPtr = IntPtr.Zero;
                if (this.IsFromThisProcess() && !this.IsFromThisAppDomain())
                {
                    try
                    {
                        bool flag;
                        intPtr = ((__ComObject)ret).GetIUnknown(out flag);
                        if (intPtr != IntPtr.Zero && !flag)
                        {
                            string typeName = this.TypeInfo.TypeName;
                            string name     = null;
                            string text     = null;
                            System.Runtime.Remoting.TypeInfo.ParseTypeAndAssembly(typeName, out name, out text);
                            Assembly assembly = FormatterServices.LoadAssemblyFromStringNoThrow(text);
                            if (assembly == null)
                            {
                                throw new RemotingException(Environment.GetResourceString("Serialization_AssemblyNotFound", new object[]
                                {
                                    text
                                }));
                            }
                            Type type = assembly.GetType(name, false, false);
                            if (type != null && !type.IsVisible)
                            {
                                type = null;
                            }
                            object typedObjectForIUnknown = Marshal.GetTypedObjectForIUnknown(intPtr, type);
                            if (typedObjectForIUnknown != null)
                            {
                                ret = typedObjectForIUnknown;
                            }
                        }
                    }
                    finally
                    {
                        if (intPtr != IntPtr.Zero)
                        {
                            Marshal.Release(intPtr);
                        }
                    }
                }
            }
            return(ret);
        }
コード例 #6
0
 private object GetCustomMarshaledCOMObject(object ret)
 {
     if (this.TypeInfo is DynamicTypeInfo)
     {
         object typedObjectForIUnknown = null;
         IntPtr nULL = Win32Native.NULL;
         if (!this.IsFromThisProcess() || this.IsFromThisAppDomain())
         {
             return(ret);
         }
         try
         {
             bool flag;
             nULL = ((__ComObject)ret).GetIUnknown(out flag);
             if (!(nULL != Win32Native.NULL) || flag)
             {
                 return(ret);
             }
             string typeName  = this.TypeInfo.TypeName;
             string str2      = null;
             string assemName = null;
             System.Runtime.Remoting.TypeInfo.ParseTypeAndAssembly(typeName, out str2, out assemName);
             Assembly assembly = FormatterServices.LoadAssemblyFromStringNoThrow(assemName);
             if (assembly == null)
             {
                 throw new RemotingException(Environment.GetResourceString("Serialization_AssemblyNotFound", new object[] { assemName }));
             }
             Type t = assembly.GetType(str2, false, false);
             if ((t != null) && !t.IsVisible)
             {
                 t = null;
             }
             typedObjectForIUnknown = Marshal.GetTypedObjectForIUnknown(nULL, t);
             if (typedObjectForIUnknown != null)
             {
                 ret = typedObjectForIUnknown;
             }
         }
         finally
         {
             if (nULL != Win32Native.NULL)
             {
                 Marshal.Release(nULL);
             }
         }
     }
     return(ret);
 }
コード例 #7
0
        [System.Security.SecurityCritical]  // auto-generated
        private Object GetCustomMarshaledCOMObject(Object ret)
        {
#if FEATURE_COMINTEROP
            // Some special work we need to do for __COMObject
            // (Note that we use typeInfo to detect this case instead of
            // calling GetType on 'ret' so as to not refine the proxy)
            DynamicTypeInfo dt = this.TypeInfo as DynamicTypeInfo;
            if (dt != null)
            {
                // This is a COMObject type ... we do the special work
                // only if it is from the same process but another appDomain
                // We rely on the x-appDomain channel data in the objRef
                // to provide us with the answers.
                Object ret1 = null;
                IntPtr pUnk = IntPtr.Zero;
                if (IsFromThisProcess() && !IsFromThisAppDomain())
                {
                    try
                    {
                        bool fIsURTAggregated;
                        pUnk = ((__ComObject)ret).GetIUnknown(out fIsURTAggregated);
                        if (pUnk != IntPtr.Zero && !fIsURTAggregated)
                        {
                            // The RCW for an IUnk is per-domain. This call
                            // gets (or creates) the RCW for this pUnk for
                            // the current domain.
                            String srvTypeName = TypeInfo.TypeName;
                            String typeName    = null;
                            String assemName   = null;

                            System.Runtime.Remoting.TypeInfo.ParseTypeAndAssembly(srvTypeName, out typeName, out assemName);
                            BCLDebug.Assert((null != typeName) && (null != assemName), "non-null values expected");

                            Assembly asm = FormatterServices.LoadAssemblyFromStringNoThrow(assemName);
                            if (asm == null)
                            {
                                BCLDebug.Trace("REMOTE", "ObjRef.GetCustomMarshaledCOMObject. AssemblyName is: ", assemName, " but we can't load it.");
                                throw new RemotingException(Environment.GetResourceString("Serialization_AssemblyNotFound", assemName));
                            }

                            Type serverType = asm.GetType(typeName, false, false);
                            if (serverType != null && !serverType.IsVisible)
                            {
                                serverType = null;
                            }
                            BCLDebug.Assert(serverType != null, "bad objRef!");

                            ret1 = InteropServices.Marshal.GetTypedObjectForIUnknown(pUnk, serverType);
                            if (ret1 != null)
                            {
                                ret = ret1;
                            }
                        }
                    }
                    finally
                    {
                        if (pUnk != IntPtr.Zero)
                        {
                            InteropServices.Marshal.Release(pUnk);
                        }
                    }
                }
            }
#endif // FEATURE_COMINTEROP
            return(ret);
        }
コード例 #8
0
        // GetRealObject uses the data we have in m_data and m_unityType to do a lookup on the correct
        // object to return.  We have specific code here to handle the different types which we support.
        // The reflection types (Assembly, Module, and Type) have to be looked up through their static
        // accessors by name.
        public virtual Object GetRealObject(StreamingContext context)
        {
            Assembly assem;

            BCLDebug.Trace("SER", "[GetRealObject] UnityType:", m_unityType);

            switch (m_unityType)
            {
            case EmptyUnity:
                BCLDebug.Trace("SER", "[GetRealObject]Returning Empty.Value");
                BCLDebug.Trace("SER", "[GetRealObject]Empty's value is: ", Empty.Value, "||");
                return(Empty.Value);

            case NullUnity:
                return(DBNull.Value);

            case MissingUnity:
                return(Missing.Value);

            case RuntimeTypeUnity:
                if (m_data == null || m_data.Length == 0 || m_assemName == null)
                {
                    BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Type. Data is: ", m_data);
                    throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
                }
                if (m_assemName.Length == 0)
                {
                    return(RuntimeType.GetTypeInternal(m_data, false, false, false));
                }

                assem = FormatterServices.LoadAssemblyFromStringNoThrow(m_assemName);
                if (assem == null)
                {
                    BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Type. AssemblyName is: ", m_assemName, " but we can't load it.");
                    throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
                }

                Type t = assem.GetTypeInternal(m_data, false, false, false);

                return(t);

            case ModuleUnity:
                if (m_data == null || m_data.Length == 0 || m_assemName == null)
                {
                    BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Module. Data is: ", m_data);
                    throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
                }
                assem = FormatterServices.LoadAssemblyFromStringNoThrow(m_assemName);
                if (assem == null)
                {
                    BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Module. AssemblyName is: ", m_assemName, " but we can't load it.");
                    throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
                }

                Module namedModule = assem.GetModule(m_data);
                if (namedModule == null)
                {
                    throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFindModule"));
                }
                return(namedModule);

            case AssemblyUnity:
                if (m_data == null || m_data.Length == 0 || m_assemName == null)
                {
                    BCLDebug.Log("UnitySerializationHolder.GetRealObject.  Assembly. Data is: " + ((m_data == null)?"<null>":m_data));
                    throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
                }
                assem = FormatterServices.LoadAssemblyFromStringNoThrow(m_assemName);
                if (assem == null)
                {
                    BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Module. AssemblyName is: ", m_assemName, " but we can't load it.");
                    throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
                }

                return(assem);

            default:
                //This should never happen because we only use the class internally.
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUnity"));
            }
        }
コード例 #9
0
        private Delegate GetDelegate(DelegateEntry de)
        {
            Delegate d;

            if (de.methodName == null || de.methodName.Length == 0)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
            }

            Assembly assem = FormatterServices.LoadAssemblyFromStringNoThrow(de.assembly);

            if (assem == null)
            {
                BCLDebug.Trace("SER", "[DelegateSerializationHolder.ctor]: Unable to find assembly for TargetType: ", de.assembly);
                throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_AssemblyNotFound"), de.assembly));
            }

            Type type = assem.GetTypeInternal(de.type, false, false, false);

            assem = FormatterServices.LoadAssemblyFromStringNoThrow(de.targetTypeAssembly);
            if (assem == null)
            {
                BCLDebug.Trace("SER", "[DelegateSerializationHolder.ctor]: Unable to find assembly for TargetType: ", de.targetTypeAssembly);
                throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_AssemblyNotFound"), de.targetTypeAssembly));
            }

            Type targetType = assem.GetTypeInternal(de.targetTypeName, false, false, false);

            if (de.target == null && targetType == null)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
            }

            if (type == null)
            {
                BCLDebug.Trace("SER", "[DelegateSerializationHolder.GetRealObject]Missing Type");
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
            }

            if (targetType == null)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState"));
            }

            Object target = null;

            if (de.target != null) //We have a delegate to a non-static object
            {
                target = RemotingServices.CheckCast(de.target, targetType);
                d      = Delegate.CreateDelegate(type, target, de.methodName);
            }
            else
            {
                //For a static delegate
                d = Delegate.CreateDelegate(type, targetType, de.methodName);
            }

            // We will refuse to create delegates to methods that are non-public.
            MethodInfo mi = d.Method;

            if (mi != null)
            {
                if (!mi.IsPublic)
                {
                    throw new SerializationException(
                              Environment.GetResourceString("Serialization_RefuseNonPublicDelegateCreation"));
                }
            }

            return(d);
        }