Some code Test SecurityCritical

 

        // test SecurityCritical, SecurityTransparent

        //shaoc 18-11-27

        static void Main(string[] args)

        {

           

            Console.WriteLine("hi ");

 

            ClassLibrary1.Class1 c1 = new ClassLibrary1.Class1 ();  // set transparent , exc .  Unhandled Exception: System.MethodAccessException: Attempt by security transparent method 'ConsoleApp1.Program.Main(System.String[])' to access security critical method 'ClassLibrary1.Class1..ctor()' failed.

            c1.funPublic();

 

            //AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;  // set transparent , exc

            //Unhandled Exception: System.MethodAccessException: Attempt by security transparent method 'ConsoleApp1.Program.Main(System.String[])' to access security critical method 'System.AppDomain.add_UnhandledException(System.UnhandledExceptionEventHandler)' failed.

 

            //AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            //console   SecurityTransparent     SecurityTransparent

            //library   default                 SecurityTransparent

            //result    ex                      ok

 

 

        }

 

        private static void CurrentDomain_ProcessExit(object sender, EventArgs e)

        {

            Console.WriteLine("CurrentDomain_ProcessExit");

        }

 

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

        {

            Console.WriteLine("UnhandledException: " + e.ToString());

            Environment.Exit(-1);

        }

 

D:\Users\fwtlaba-local\source\repos\ConsoleApp1\ConsoleApp1\Properties\AssemblyInfo.cs

//[assembly: System.Security.SecurityTransparent]

//Unhandled Exception: System.MethodAccessException: Attempt by security transparent method 'ConsoleApp1.Program.Main(System.String[])' to access security critical method 'ClassLibrary1.Class1..ctor()' failed.

//   at ConsoleApp1.Program.Main(String[] args)

 

 

//[assembly: System.Security.SecurityCritical]

//Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.An operation is not legal in the current state. (Exception from HRESULT: 0x80131509) ---> System.InvalidOperationException: SecurityTransparent and SecurityCritical attributes cannot be applied to the assembly scope at the same time.

 

 

//[assembly: System.Security.SecuritySafeCritical]

//Error CS0592  Attribute 'System.Security.SecuritySafeCritical' is not valid on this declaration type. It is only valid on 'class, struct, enum, constructor, method, field, interface, delegate' declarations.ConsoleApp1 

//[assembly: System.Security.SuppressUnmanagedCodeSecurity]

//Error CS0592  Attribute 'System.Security.SuppressUnmanagedCodeSecurity' is not valid on this declaration type. It is only valid on 'class, method, interface, delegate' declarations.ConsoleApp1 

 

 

//[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.None)]

Unhandled Exception: System.IO.FileLoadException: Assembly 'ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' specified an unknown security rule set.

//[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

ok

//[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level2)]

ok

 

D:\Users\fwtlaba-local\source\repos\ClassLibrary1\Class1.cs

        //[System.Security.SecuritySafeCritical]   

        public void funPublic()

        {

            Console.WriteLine(nameof(funPublic) );

        }

 

        internal void funInt()

        {

            Console.WriteLine(nameof(funPublic) +" 2" );

        }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值