gpt4 book ai didi

c# - 在 Visual Studio 2013 中调试时看不到类级变量

转载 作者:可可西里 更新时间:2023-11-01 09:14:21 27 4
gpt4 key购买 nike

我在 VS 2013 中调试一些 C# 代码时观察到一些奇怪的行为。当我将鼠标悬停在当前方法范围内的任何变量上时,我可以看到变量的信息。在下面的屏幕截图中,您可以看到 ivSimulation 已固定并显示信息。但是,即使您看不出来,我将鼠标悬停在 this._simulator 上,也没有显示任何内容。 QuickWatch 也不显示任何内容。

enter image description here

另一位同事也遇到了同样的问题。我们已经尝试清除我们的文件夹并再次获取最新的。我们还尝试将 VS 中的设置(工具 -> 选项 -> 调试 -> 常规 -> 使用托管兼容模式)更改为选中状态,但这也没有用。显然这对其他人有用。这在 VS 2012 中工作得很好。

有什么想法吗?如何让类级变量显示在调试器中?

编辑:另一 block 拼图

如果我将鼠标悬停在 this 上,我会看到它是一个透明代理。不确定为什么会这样。

enter image description here

另一篇:

this 指派生自 ContextBoundObject 的类。我们这样做是为了可以使用拦截来进行日志记录和异常处理。也许这就是原因。

我错了;这在 VS2012 中不起作用。也许我以前从未注意到它。

如果我尝试在即时窗口中显示值,这就是我得到的:

? this._coater.Equipment.Line.Unit.Plant.Site.SiteId Cannot obtain fields or call methods on the instance of type 'Company.Mes.Core.Components.Logic.ModuleDerating.StandardDeratingComponentLogic' because it is a proxy to a remote object.

最佳答案

因为this是透明代理

以下屏幕截图通过底部的示例代码演示了此问题。

首先创建真实对象并将鼠标悬停在该实例的 Name 属性上:

enter image description here

现在为对象创建一个代理。 enter image description here

请注意,我将鼠标悬停在该实例上以表明它是一个透明代理。

现在将鼠标悬停在透明代理实例的 Name 属性上。 enter image description here

什么都没有显示!透明代理巧妙地编码了对底层对象的调用,但 IDE 显然无法弄清楚,因为返回的代理对象是基于 Foo 类动态生成的类。

以及完整性的输出。

enter image description here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Text;

namespace ConsoleApplication27
{
class Program
{
static void Main(string[] args)
{
Foo foo = new Foo(){ Name = "My Foo1" };

Console.WriteLine(foo.Name);

FooProxy fooProxy = new FooProxy(foo);

Foo proxiedFoo = (Foo)fooProxy.GetTransparentProxy();

Console.WriteLine(proxiedFoo.Name);
}
}

public class Foo : MarshalByRefObject
{
public string Name { get; set; }
}

public class FooProxy
: RealProxy
{
private Foo _target;

public FooProxy(Foo target) : base(typeof(Foo))
{
this._target = target;
}

public override IMessage Invoke(IMessage msg)
{
return InvokeRemoteCall((IMethodCallMessage)msg, this._target);
}

/// <summary>
/// Invokes the remote call.
/// </summary>
/// <param name="methodCall">The method call.</param>
/// <param name="target">The target.</param>
/// <returns>A <see cref="ReturnMessage"/></returns>
private static IMessage InvokeRemoteCall(IMethodCallMessage methodCall, object target)
{
MethodInfo method = methodCall.MethodBase as MethodInfo;

object callResult = (target != null) ? method.Invoke(target, methodCall.InArgs) : null;

LogicalCallContext context = methodCall.LogicalCallContext;

var query = method.GetParameters().Where(param => ((ParameterInfo)param).IsOut);

ParameterInfo[] outParameters = query.ToArray();

return new ReturnMessage(callResult, outParameters, outParameters.Count(), context, methodCall);
}
}
}

关于c# - 在 Visual Studio 2013 中调试时看不到类级变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22257304/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com