C# - 马歇尔按值问题!

发布于 2024-10-09 01:28:02 字数 2463 浏览 7 评论 0原文

事情是这样的,我在使用远程机制“按值编组”创建新对象时遇到问题。

这是我的类:

  [Serializable]
    internal class Empleado_MBV
    {
        public Empleado_MBV()
        {
            Id = 123456789;
            Nombres = "NotEntry";
            Apellidos = "NotEntry";
            FechaNacimiento = DateTime.MinValue;
            Direccion = "NotEntry";
            Metapreferencias = "NotEntry";
        }

        private List<Multas> _multas;

        internal List<Multas> Multas
        {
            get { return _multas; }
            set { _multas = value; }
        }

        private int _id;

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        private string _nombres;

        public string Nombres
        {
            get { return _nombres; }
            set { _nombres = value; }
        }
        private string _apellidos;

        public string Apellidos
        {
            get { return _apellidos; }
            set { _apellidos = value; }
        }
        private DateTime _FecNac;

        public DateTime FechaNacimiento
        {
            get { return _FecNac; }
            set { _FecNac = value; }
        }
        private string _direccion;

        public string Direccion
        {
            get { return _direccion; }
            set { _direccion = value; }
        }
        private string _metapreferencias;

        public string Metapreferencias
        {
            get { return _metapreferencias; }
            set { _metapreferencias = value; }
        }

        public string _AppDomainHost
        {
            get { return AppDomain.CurrentDomain.FriendlyName.ToString(); }
        }
    }

但是当我尝试在另一个“appdomain”中创建对象时,“Empleado”的属性“_AppDomainHost”不显示我创建的“appdomain”,而是默认显示“appdomain”。一些想法?

AppDomain ad1 = AppDomain.CreateDomain("NewAppDomain");
        //Crear new object in my new AD.
        Empleado_MBV mbv_emp =      (Empleado_MBV)ad1.CreateInstanceFromAndUnwrap("DEMO_MBV_MBR.exe", "DEMO_MBV_MBR.Empleado_MBV");

        Console.WriteLine(AppDomain.CurrentDomain.FriendlyName.ToString());
        Console.WriteLine("MBV : {0}",mbv_emp._AppDomainHost.ToString());

        Console.ReadLine();

结果:

DEMO_MBV_MBR.vshost.exe

MBV : DEMO_MBV_MBR.vshost.exe

我想要的结果:

DEMO_MBV_MBR.vshost.exe

MBV : NewAppDomain

Here is the thing, I have a problem creating a new object using the remote mechanism "marshal by value".

Here is my class:

  [Serializable]
    internal class Empleado_MBV
    {
        public Empleado_MBV()
        {
            Id = 123456789;
            Nombres = "NotEntry";
            Apellidos = "NotEntry";
            FechaNacimiento = DateTime.MinValue;
            Direccion = "NotEntry";
            Metapreferencias = "NotEntry";
        }

        private List<Multas> _multas;

        internal List<Multas> Multas
        {
            get { return _multas; }
            set { _multas = value; }
        }

        private int _id;

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        private string _nombres;

        public string Nombres
        {
            get { return _nombres; }
            set { _nombres = value; }
        }
        private string _apellidos;

        public string Apellidos
        {
            get { return _apellidos; }
            set { _apellidos = value; }
        }
        private DateTime _FecNac;

        public DateTime FechaNacimiento
        {
            get { return _FecNac; }
            set { _FecNac = value; }
        }
        private string _direccion;

        public string Direccion
        {
            get { return _direccion; }
            set { _direccion = value; }
        }
        private string _metapreferencias;

        public string Metapreferencias
        {
            get { return _metapreferencias; }
            set { _metapreferencias = value; }
        }

        public string _AppDomainHost
        {
            get { return AppDomain.CurrentDomain.FriendlyName.ToString(); }
        }
    }

But when I try to create an object in another "appdomain", the property "_AppDomainHost" of "Empleado" does not show the "appdomain" I had created, but show the "appdomain" by default. Some ideas?

AppDomain ad1 = AppDomain.CreateDomain("NewAppDomain");
        //Crear new object in my new AD.
        Empleado_MBV mbv_emp =      (Empleado_MBV)ad1.CreateInstanceFromAndUnwrap("DEMO_MBV_MBR.exe", "DEMO_MBV_MBR.Empleado_MBV");

        Console.WriteLine(AppDomain.CurrentDomain.FriendlyName.ToString());
        Console.WriteLine("MBV : {0}",mbv_emp._AppDomainHost.ToString());

        Console.ReadLine();

Result:

DEMO_MBV_MBR.vshost.exe

MBV : DEMO_MBV_MBR.vshost.exe

The result that I want:

DEMO_MBV_MBR.vshost.exe

MBV : NewAppDomain

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2024-10-16 01:28:02

您需要将 AppDomain 存储在 Empleado_MBV 的构造函数中。

您现在正在做的是使用其 Current 静态属性显示当前的 AppDomain。它将返回正在执行当前代码的AppDomain

示例:

private string _appDomainHost;
public string _AppDomainHost
{
    get { return _appDomainHost; }
}

在构造函数中:

_appDomainHost = AppDomain.CurrentDomain.FriendlyName.ToString();

You need to store AppDomain in Empleado_MBV's constructor.

What you are doing right now is displaying current AppDomain using its Current static property. It will return the AppDomain where current code is being executed.

Example:

private string _appDomainHost;
public string _AppDomainHost
{
    get { return _appDomainHost; }
}

and in constructor:

_appDomainHost = AppDomain.CurrentDomain.FriendlyName.ToString();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文