private static void GetPermissions() { if (!m_Initialized) { //test RelectionPermission CodeAccessPermission securityTest; try { securityTest = new ReflectionPermission(PermissionState.Unrestricted); securityTest.Demand(); m_ReflectionPermission = true; } catch { //code access security error m_ReflectionPermission = false; } //test WebPermission try { securityTest = new WebPermission(PermissionState.Unrestricted); securityTest.Demand(); m_WebPermission = true; } catch { //code access security error m_WebPermission = false; } //test WebHosting Permission (Full Trust) try { securityTest = new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted); securityTest.Demand(); m_AspNetHostingPermission = true; } catch { //code access security error m_AspNetHostingPermission = false; } m_Initialized = true; //Test for Unmanaged Code permission try { securityTest = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); securityTest.Demand(); m_UnManagedCodePermission = true; } catch (Exception e) { m_UnManagedCodePermission = false; } } }
public PrivateObjectTester (object instance) { perm = new ReflectionPermission(PermissionState.Unrestricted); perm.Demand(); type = Type.GetTypeFromHandle(Type.GetTypeHandle(instance)); this.instance = instance; }
private Type type; // type of class to manage #endregion Fields #region Constructors public PrivateObjectReflector(string qualifiedTypeName, params object[] args) { perm = new ReflectionPermission(PermissionState.Unrestricted); perm.Demand(); type = Type.GetType(qualifiedTypeName); Type[] types = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { types[i] = args[i].GetType(); } instance = type.GetConstructor(bindingFlags, null, types, null).Invoke(args); }
private static void GetPermissions() { if (!m_Initialized) { // test RelectionPermission System.Security.CodeAccessPermission securityTest; try { securityTest = new ReflectionPermission(PermissionState.Unrestricted); securityTest.Demand(); m_ReflectionPermission = true; } catch { m_ReflectionPermission = false; } // test WebPermission try { securityTest = new System.Net.WebPermission(PermissionState.Unrestricted); securityTest.Demand(); m_WebPermission = true; } catch { m_WebPermission = false; } // test WebHosting Permission (Full Trust) try { securityTest = new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted); securityTest.Demand(); m_AspNetHostingPermission = true; } catch { m_AspNetHostingPermission = false; } m_Initialized = true; } }
internal void SetAttributes(IDataReader reader) { // allow access to private fields ReflectionPermission perm = new ReflectionPermission(ReflectionPermissionFlag.NoFlags); perm.Demand(); perm.Assert(); try { IDictionary TimeSheetFieldMappings = GetDataLink().FieldMappings; _log.Debug("SetAttributes: starting for loop (" + this.GetType().FullName + ")"); for (int i = 0; i < reader.FieldCount; i++) { try { // Get the field mapping entry corresponding to the database column name TimeSheetFieldMap TimeSheetFieldMap = null; foreach (TimeSheetFieldMap TimeSheetFieldMap2 in TimeSheetFieldMappings.Values) { if (TimeSheetFieldMap2.FieldName == reader.GetName(i)) { TimeSheetFieldMap = TimeSheetFieldMap2; break; } } if (TimeSheetFieldMap == null) { //throw new ApplicationException(string.Format("Could not locate {0} in field mappings.", reader.GetName(i))); } // Read the object from the database. This may be a plain value // Enum stored as an integer in the database object value; if (!reader.IsDBNull(i)) { if (TimeSheetFieldMap.IsEnum) { // the database field holds the int value for an enum _log.Debug("SetAttributes: Setting enum value for " + TimeSheetFieldMap.AttributeName); object enumValue = GetObjectFromDatabase(reader, i); value = Enum.ToObject(TimeSheetFieldMap.EnumType, enumValue); } else { // the database field holds the attribute value _log.Debug("SetAttributes: Setting direct value for " + TimeSheetFieldMap.AttributeName); value = GetObjectFromDatabase(reader, i); } } else { value = null; } _log.Debug("SetAttributes: now setting field " + TimeSheetFieldMap.FieldInfo + " to " + value); // set the instance's field to the value try { TimeSheetFieldMap.FieldInfo.SetValue(this, value); } catch { _log.Debug("Exception caught in FieldInfo.SetValue setting field {0} to {1}.", TimeSheetFieldMap.FieldInfo, value); //throw; } _log.Debug("SetAttributes: Setting " + TimeSheetFieldMap.FieldName + " to " + value); } catch (Exception e) { _log.Debug("Exception caught reading {0}, column {1}, column name '{2}'.", e, this.GetType().Name, i, reader.GetName(i)); //throw; } } } finally { CodeAccessPermission.RevertAssert(); } _log.Debug("SetAttributes: done (" + this.GetType().FullName + ")"); }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { if ((Thread.CurrentThread.ThreadState & (ThreadState.AbortRequested | ThreadState.Aborted)) != 0) { return; } if (ShouldSuppressLogMessages) return; using (SuppressLogMessages()) { try { var perm = new ReflectionPermission(PermissionState.Unrestricted); perm.Demand(); } catch (SecurityException) { //Cannot raise messages if this permission is denied. return; } EventAppDomainException.Publish(null, null, e.ExceptionObject as Exception); } }
private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) { if ((Thread.CurrentThread.ThreadState & (ThreadState.AbortRequested | ThreadState.Aborted)) != 0) { return; } if (ShouldSuppressFirstChanceLogMessages) return; using (SuppressFirstChanceExceptionLogMessages()) { try { var perm = new ReflectionPermission(PermissionState.Unrestricted); perm.Demand(); } catch (SecurityException) { //Cannot raise messages if this permission is denied. return; } try { EventFirstChanceException.Publish(null, null, e.Exception); } catch (Exception) { //swallow any exceptions. } ThreadLocalThreadStack.Value.PreviousFirstChanceExceptionSequenceNumber++; } }