这两条错误消息的原因是什么?

时间:2022-08-29 22:45:23

First of all, I'd like to say that this site is great!

首先,我想说这个网站很棒!

My question is, what are the reasons for the following 2 error messages?

我的问题是,以下2条错误消息的原因是什么?

1) In VB.NET (I know this is a C# forum but my next question is from C# experience), property evaluation failed (I do this when putting a watch on an exception variable).

1)在VB.NET中(我知道这是一个C#论坛,但我的下一个问题来自C#经验),属性评估失败(我在监视异常变量时这样做)。

2) In C#, method or class (Can't remember which) does not have a constructor. I think I got this with HttpContext or HttpApplication, which is a class if I remember correctly? Pretty sure it is as it has its own properties and methods.

2)在C#中,方法或类(不记得哪个)没有构造函数。我想我用HttpContext或HttpApplication得到了这个,如果我没记错的话,这是一个类吗?很确定它是有自己的属性和方法。

Thanks

3 个解决方案

#1


3  

1) Could be any number of reasons. Some properties just don't work nicely in a debugger. (Imagine watching DateTime.Now for changes!)

1)可能有多种原因。某些属性在调试器中不能很好地工作。 (想象一下,观看DateTime.Now进行更改!)

2) You're trying to create an instance of a class which doesn't have an appropriate accessible constructor. Usually either the class only has static members, or there's a static member you're meant to use to get an instance. (Having said that, both the classes you've mentioned have public constructors.)

2)您正在尝试创建一个没有适当的可访问构造函数的类的实例。通常,该类只有静态成员,或者有一个静态成员,您可以使用它来获取实例。 (话虽如此,你提到的两个类都有公共构造函数。)

More precise error messages and situation descriptions would be helpful.

更准确的错误消息和情境描述会很有帮助。

#2


2  

I'd probably want to see code snippets to give you real answers, but my psychic detection powers are telling me that #2 is most likely that you are trying to do something like:

我可能希望看到代码片段给你真正的答案,但我的心灵检测能力告诉我#2很可能是你试图做的事情:

HttpContext context = new HttpContext;

This isn't the way you'd approach that. Instead, you would use its built-in factory method to access the current one:

这不是你接近的方式。相反,您将使用其内置工厂方法来访问当前的工厂方法:

HttpContext context = HttpContext.Current;

(Ditto for HttpApplication.)

(同样适用于HttpApplication。)

I can't help with #1 without seeing some representative code. And don't worry, this isn't a C#-specific forum, it's for all programming languages and platforms. :)

如果没有看到一些有代表性的代码,我无法帮助#1。不用担心,这不是一个C#特定的论坛,它适用于所有编程语言和平台。 :)

#3


0  

First of all, apologies for making a duplicate thread (couldn't see this one so made another).

首先,为制作一个重复的线程道歉(看不到这一个,所以另一个)。

1) That makes sense. Watching datetime.now for changes will just display the time @ the time of adding a watch, cache that value, and then get the new value (Time) when checking again.

1)这是有道理的。观看datetime.now进行更改只会显示时间@添加监视的时间,缓存该值,然后再次检查时获取新值(时间)。

2) John Rudy: you are spot on. That is what I was doing. So HttpContext.Current gives me back the httpcontext object to work with, I see.

2)约翰鲁迪:你是现场的。这就是我在做的事情。所以HttpContext.Current让我回到了httpcontext对象,我明白了。

#1


3  

1) Could be any number of reasons. Some properties just don't work nicely in a debugger. (Imagine watching DateTime.Now for changes!)

1)可能有多种原因。某些属性在调试器中不能很好地工作。 (想象一下,观看DateTime.Now进行更改!)

2) You're trying to create an instance of a class which doesn't have an appropriate accessible constructor. Usually either the class only has static members, or there's a static member you're meant to use to get an instance. (Having said that, both the classes you've mentioned have public constructors.)

2)您正在尝试创建一个没有适当的可访问构造函数的类的实例。通常,该类只有静态成员,或者有一个静态成员,您可以使用它来获取实例。 (话虽如此,你提到的两个类都有公共构造函数。)

More precise error messages and situation descriptions would be helpful.

更准确的错误消息和情境描述会很有帮助。

#2


2  

I'd probably want to see code snippets to give you real answers, but my psychic detection powers are telling me that #2 is most likely that you are trying to do something like:

我可能希望看到代码片段给你真正的答案,但我的心灵检测能力告诉我#2很可能是你试图做的事情:

HttpContext context = new HttpContext;

This isn't the way you'd approach that. Instead, you would use its built-in factory method to access the current one:

这不是你接近的方式。相反,您将使用其内置工厂方法来访问当前的工厂方法:

HttpContext context = HttpContext.Current;

(Ditto for HttpApplication.)

(同样适用于HttpApplication。)

I can't help with #1 without seeing some representative code. And don't worry, this isn't a C#-specific forum, it's for all programming languages and platforms. :)

如果没有看到一些有代表性的代码,我无法帮助#1。不用担心,这不是一个C#特定的论坛,它适用于所有编程语言和平台。 :)

#3


0  

First of all, apologies for making a duplicate thread (couldn't see this one so made another).

首先,为制作一个重复的线程道歉(看不到这一个,所以另一个)。

1) That makes sense. Watching datetime.now for changes will just display the time @ the time of adding a watch, cache that value, and then get the new value (Time) when checking again.

1)这是有道理的。观看datetime.now进行更改只会显示时间@添加监视的时间,缓存该值,然后再次检查时获取新值(时间)。

2) John Rudy: you are spot on. That is what I was doing. So HttpContext.Current gives me back the httpcontext object to work with, I see.

2)约翰鲁迪:你是现场的。这就是我在做的事情。所以HttpContext.Current让我回到了httpcontext对象,我明白了。