Exemplo n.º 1
0
        internal override PageFunctionBase ResumePageFunction()
        {
            PageFunctionBase pageFunction;

            Invariant.Assert(this._typeName.Value != null, "JournalEntry does not contain the Type for the PageFunction to be created");

            //First try Type.GetType from the saved typename, then try Activator.CreateInstanceFrom
            //Type.GetType - Since the typename is fullyqualified
            //we will end up using the default binding mechanism to locate and bind to the assembly.
            //If the assembly was not a strongly named one nor is present in the APPBASE, this will
            //fail.

            Type pfType = Type.GetType(this._typeName.Value);

            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
            try
            {
                pageFunction = (PageFunctionBase)Activator.CreateInstance(pfType);
            }
            catch (Exception ex)
            {
                throw new Exception(SR.Get(SRID.FailedResumePageFunction, this._typeName.Value), ex);
            }
            finally
            {
                ReflectionPermission.RevertAssert();
            }

            InitializeComponent(pageFunction);

            RestoreState(pageFunction);

            return(pageFunction);
        }
        public bool makeTheRequestFormDataEditable()
        {
            try
            {
                object objectToReflect  = HttpContext.Current.Request.Form;
                string stringObjectType = "MakeReadWrite";

                // Assert the retrival of information from a Private Method
                ReflectionPermission reflectionPerm = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation);
                reflectionPerm.Assert();

                MethodInfo objTempMethodType = objectToReflect.GetType().GetMethod(
                    stringObjectType, BindingFlags.Public | BindingFlags.NonPublic |
                    BindingFlags.Instance, null, CallingConventions.Any, new Type[0] {
                }, null);

                // Revert the previous assert since it is only possible to have one active Assert
                ReflectionPermission.RevertAssert();
                // Assert the execution of a Private Method
                reflectionPerm = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
                reflectionPerm.Assert();

                object invokeResult =
                    objTempMethodType.Invoke(
                        objectToReflect, BindingFlags.Public | BindingFlags.NonPublic |
                        BindingFlags.Instance | BindingFlags.InvokeMethod, null, new object[0] {
                }, null);
                return(true);
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.Message);
                return(false);
            }
        }
Exemplo n.º 3
0
        static XPathDocumentWriter()
        {
            ReflectionPermission perm = new ReflectionPermission(PermissionState.Unrestricted);

            perm.Flags = ReflectionPermissionFlag.MemberAccess;

            try
            {
                perm.Assert();

                Type t = typeof(XPathDocument);
                defaultConstructor = t.GetConstructor(
                    BindingFlags.NonPublic | BindingFlags.Instance, null,
                    Type.EmptyTypes,
                    new ParameterModifier[0]);
                Debug.Assert(defaultConstructor != null, ".NET Framework implementation changed");

                loadWriterMethod = t.GetMethod("LoadFromWriter", BindingFlags.Instance | BindingFlags.NonPublic);
                Debug.Assert(loadWriterMethod != null, ".NET Framework implementation changed");
            }
            finally
            {
                ReflectionPermission.RevertAssert();
            }
        }
Exemplo n.º 4
0
        public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
        {
            // From MSDN "The default InitializeNewDomain implementation does nothing"
            // base.InitializeNewDomain(appDomainInfo);
            InitializationFlags = AppDomainManagerInitializationOptions.RegisterWithHost;

            // Beginning with the .NET Framework 4, you can use this method to sandbox the default
            // application domain at application startup, or to modify the sandbox of a new application domain.
            // To do this, adjust the DefaultGrantSet and FullTrustAssemblies properties on the ApplicationTrust
            // object that is assigned to the AppDomainSetup.ApplicationTrust property of appDomainInfo, before
            // you initialize the application domain.

            int currentDomainId = AppDomain.CurrentDomain.Id;

            // Hack: call System.Diagnostics.Debug.WriteLine before setting the domain_AssemblyLoad event,
            // or the loading will trigger a loop.
            System.Diagnostics.Debug.WriteLine("Initializing domain " + currentDomainId);


            //if (AppDomain.CurrentDomain.IsDefaultAppDomain()) {

            new ReflectionPermission(PermissionState.Unrestricted).Assert();

            AppDomain.CurrentDomain.AssemblyResolve += domain_AssemblyResolve;
            AppDomain.CurrentDomain.AssemblyLoad    += domain_AssemblyLoad;

            AppDomain.CurrentDomain.DomainUnload += (sender, e) => {
                OnDomainUnload(currentDomainId);
            };
            //AppDomain.CurrentDomain.FirstChanceException += (sender, e) => {
            //   OnFirstChanceException(currentDomainId, e.Exception);
            //};
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
                OnUnhandledException(currentDomainId, e.ExceptionObject);
            };

            ReflectionPermission.RevertAssert();


            // REVIEW: the assumption, for now, is that the thread that creates the AppDomain is the
            // "main" thread, the one that will execute the snippet.
            // IF THIS CHANGES, there will be the need to review this bit
            mainThreadManagedId = Thread.CurrentThread.ManagedThreadId;
        }
Exemplo n.º 5
0
        internal void _Attach(Object caller, PageFunctionBase child)
        {
            ReturnEventSaverInfo[] list = null;

            list = _returnList;

            if (list != null)
            {
                Debug.Assert(caller != null, "Caller should not be null");
                for (int i = 0; i < list.Length; i++)
                {
                    //
                    // Future notes: how do we handle listeners that were not on the calling pagefunction ?
                    // E.g. - if we had a listener to OnFinish from a Button on the calling page.
                    //  "Return event never fired from PageFunction hosted in its own window"
                    //
                    if (string.Compare(_returnList[i]._targetTypeName, caller.GetType().AssemblyQualifiedName, StringComparison.Ordinal) != 0)
                    {
                        throw new NotSupportedException(SR.Get(SRID.ReturnEventHandlerMustBeOnParentPage));
                    }

                    Delegate d;
                    try
                    {
                        new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert(); // BlessedAssert

                        d = Delegate.CreateDelegate(
                            Type.GetType(_returnList[i]._delegateTypeName),
                            caller,
                            _returnList[i]._delegateMethodName);
                    }
                    catch (Exception ex)
                    {
                        throw new NotSupportedException(SR.Get(SRID.ReturnEventHandlerMustBeOnParentPage), ex);
                    }
                    finally
                    {
                        ReflectionPermission.RevertAssert();
                    }

                    child._AddEventHandler(d);
                }
            }
        }
        internal void _Attach(Object caller, PageFunctionBase child)
        {
            ReturnEventSaverInfo[] list = null;

            list = _returnList;

            if (list != null)
            {
                Debug.Assert(caller != null, "Caller should not be null");
                for (int i = 0; i < list.Length; i++)
                {
                    //
                    //



                    if (string.Compare(_returnList[i]._targetTypeName, caller.GetType().AssemblyQualifiedName, StringComparison.Ordinal) != 0)
                    {
                        throw new NotSupportedException(SR.Get(SRID.ReturnEventHandlerMustBeOnParentPage));
                    }

                    Delegate d;
                    try
                    {
                        new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert(); // BlessedAssert

                        d = Delegate.CreateDelegate(
                            Type.GetType(_returnList[i]._delegateTypeName),
                            caller,
                            _returnList[i]._delegateMethodName);
                    }
                    catch (Exception ex)
                    {
                        throw new NotSupportedException(SR.Get(SRID.ReturnEventHandlerMustBeOnParentPage), ex);
                    }
                    finally
                    {
                        ReflectionPermission.RevertAssert();
                    }

                    child._AddEventHandler(d);
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Copy all of the internal fields.
 /// </summary>
 public void CopyFields(ref object Instance, ref Array Fields, ref object Source)
 {
     try
     {
         //** When used with .Net Remoting hosted by IIS, even with Full trust,
         //** f.SetValue fails with a permission exception.
         //** This asset grants the required permissions so that the f.SetValue works.
         ReflectionPermission rp = new ReflectionPermission(PermissionState.Unrestricted);
         rp.Assert();
         foreach (PropertyInfo f in Fields)
         {
             if (f.CanWrite)
             {
                 f.SetValue(Instance, f.GetValue(Source));
             }
         }
     }
     finally
     {
         ReflectionPermission.RevertAssert();
     }
 }