简体   繁体   English

如何在控制台应用程序中获取 AppDomain.CurrentDomain.ActivationContext 的 object?

[英]How to get object of AppDomain.CurrentDomain.ActivationContext in Console application?

using System;
namespace ActivationContextSample
{
 public class Program : MarshalByRefObject
 {
    public static void Main(string[] args)
    {
        ActivationContext ac = AppDomain.CurrentDomain.ActivationContext;
        ApplicationIdentity ai = ac.Identity;
        Console.WriteLine("Full name = " + ai.FullName);
        Console.WriteLine("Code base = " + ai.CodeBase);
        Console.Read();
    }
    public void Run()
    {
        Main(new string[] { });
        Console.ReadLine();
    }
}

} }

Error: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at ActivationContextSample.Program.Main (System.String[] args) [0x0000b] in <7d43242f5912432d822ac735ddb97f04>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at ActivationContextSample.Program.Main (System.String[] args) [0x0000b] in <7d43242f5912432d822ac735ddb97f04>:0 Error: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at ActivationContextSample.Program.Main (System.String[] args) [0x0000b] in <7d43242f5912432d822ac735ddb97f04>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System .NullReferenceException:Object 引用未设置为 ActivationContextSample.Program.Main 中的 object 实例(System.String[] args)[0x0000b] in <7d4324282f59ddbf9732

如果设置断点,您应该能够看到 AppDomain.CurrentDomain.ActivationContext 为空。

Try creating executable application and run it.尝试创建可执行应用程序并运行它。 In that case you will get the required object.在这种情况下,您将获得所需的 object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 AppDomain.CurrentDomain.BaseDirectory 在控制台应用程序中定位 bin catelog? - Why is AppDomain.CurrentDomain.BaseDirectory targeting bin catelog in console application? AppDomain.CurrentDomain.DomainUnload不会在控制台应用程序中引发 - AppDomain.CurrentDomain.DomainUnload not be raised in Console app AppDomain.ActivationContext为NULL - AppDomain.ActivationContext is NULL 不会调用AppDomain.CurrentDomain.UnhandledException - AppDomain.CurrentDomain.UnhandledException does not get called 如何在AppDomain.CurrentDomain.UnhandledException处理程序中退出应用程序,并仍然确保执行finally {}块? - How to quit application in AppDomain.CurrentDomain.UnhandledException handler and still ensure that finally{} blocks execute? 从AppDomain.CurrentDomain.SetData()获取密钥 - get keys from AppDomain.CurrentDomain.SetData() 如何模拟AppDomain.CurrentDomain.BaseDirectory - How to mock AppDomain.CurrentDomain.BaseDirectory AppDomain.CurrentDomain.ProcessExit不执行Console.WriteLine - AppDomain.CurrentDomain.ProcessExit doesn't perform Console.WriteLine Application和AppDomain.CurrentDomain之间有什么区别 - What's the difference between Application and AppDomain.CurrentDomain 抑制 Application.ThreadException 和 AppDomain.CurrentDomain.UnhandledException - Suppressing Application.ThreadException and AppDomain.CurrentDomain.UnhandledException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM