'var_name' 未声明.由于其保护级别,它可能无法访问.在调试模式 [英] 'var_name'is not declared. It may be inaccessible due to its protection level.' in debug mode

查看:39
本文介绍了'var_name' 未声明.由于其保护级别,它可能无法访问.在调试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此行为在具有 Web 应用程序引用的多个类库项目的 vb.net Web 应用程序解决方案中.

This behavior is in a vb.net web application solution with multiple class library projects referenced by the web app.

代码编译通过,但是在调试模式下,引用的类库中的一些函数/子程序有局部变量显示

The code compiles, but in debug mode, some functions/subroutines in the referenced class libraries have local variables that display

'var_name' 未声明.它可能无法访问,因为它保护级别.

'var_name' is not declared. It may be inaccessible due to its protection level.

在监视和即时窗口中.

mouse_over 智能感知不适用于这些局部变量.

The mouse_over intellisense doesn't work on those local variables.

在某些子/函数中,变量的值是可访问的,直到我进入Try..Catch

In some sub/functions the variables' values are accessible until I step into a Try..Catch

传递给子/函数的所有变量都是可访问的.在类级别定义的变量也可以访问.

All variables passed into the Sub/Function are accessible. Variables defined at the class level are accessible, too.

此行为在解决方案中已存在多年的代码中是新的.子程序和函数的范围没有改变(它们是公共的).

This behavior is new in code that has been in the solution for years. The scope of the subroutines and functions have not changed (they are Public).

它也不一致.在给定的类库项目中,一个类中的公共函数/子例程将具有局部变量,您可以在其中查看它们的值,而其他类则显示如上所示的消息.

It is not consistent either. In a given class library project, public functions/subroutines in one class will have local variables where you can see their values, while others display the message shown above.

我已经尝试过的事情:

* Clean/Rebuild Solution
* Turn off Code optimizations (it has always been turned off in Debug mode)
* Enable the "Show all members for non-user objects in variables windows (Visual Studio)" option in the Debugging options.
* Import default settings for VS2012
* Update VS2012 to latest version (Update 4)
* Install VS2013 and open solution (behavior occurs there as well)
* Clear AppData cache
* In Advanced Compiler Settings, set 'Generate debug info' to both Full and pdb-only
* Remove local copy of solution and get the solution again from TFS
* All projects in the solution are set to Debug

我在 TFS 中有多个解决方案,这是显示此行为的唯一解决方案.

I have multiple solutions in TFS and this is the only solution that shows this behavior.

我有一位同事在 TFS 中获得了相同解决方案的副本,但在他的本地副本中没有发生这种行为.

I have had a colleague get a copy of the same solution in TFS and the behavior does NOT occur in his local copy.

这种行为在 VS2010 中没有发生.

This behavior did not occur in VS2010.

这是发生此行为的方法和局部变量声明的示例.如果您单步执行声明并对任何局部变量或使用局部变量的任何语句设置监视,您将看到

Here is an example of a method and local variable declarations where this behavior occurs. If you step through the declarations and set watch on any of the local variables or any statements using the local variables, you will see

'var_name' 未声明.它可能无法访问,因为它保护级别.

'var_name' is not declared. It may be inaccessible due to its protection level.

作为watch/quick watch/immediate windows中变量的值

as the value of the variable in the watch/quick watch/immediate windows

Imports System.Web

Imports System.Text

Imports SPBO

Public Class Utility1

Public oNav_inc As New Navigation_INC
'===========================================================================
'Utility1.vb
'===========================================================================
    Public Sub UTIL_EstablishActivityContext(ByRef Response As HttpResponse, ByRef page As Page, ByRef oGlobal_inc As GlobalVariables_INC)

        Dim oActivity As ENC2.Web.ActivityContext
        Dim oMHardUBO As MHUBO
        Dim oPUBO As PUBO
        Dim asGroup As String = ""
        Dim sGroup As String = ""
        Dim bActive As Boolean
        Dim g_oUserAccountBO As UserAccountBO
        Dim sImplementation As String = ""
        Dim rs As DataSet
        Dim sQuery As String
        Dim rsUser As DataSet
        Dim sUserGroups As Object
        Dim iLoop As Integer
        Dim bInternal As Boolean
        Dim g_bInternalUser As Boolean

        g_bInternalUser = False

        'rest of code

    End Sub

End Class

<小时>

更新:我继续重新格式化/重新映像我的笔记本电脑并安装了 VS2013.该问题不再出现.


UPDATE: I went ahead and reformatted/reimaged my laptop and installed VS2013. The issue is no longer appearing.

推荐答案

这并不是一个永久性的解决方案,但我确实在我为我的朋友修改的项目中找到了解决方法.虽然我无法让错误永久消失,但我发现如果受影响的页面实际上没有打开进行编辑,它不会报告这些错误.

It's not exactly a permanent solution, but I did find a workaround for this in a project I was amending for a friend of mine. Although I couldn't make the bug to go away on a permanent basis, I found that it didn't report these errors if the affected pages weren't actually open for editing.

我必须做的是保存它们,将它们从编辑器中关闭,然后编译项目.一旦我这样做了,该项目就会正确编译,并且在编译之后,即使打开页面进行编辑,它也不会再次报告这些错误(尽管最终,某些编辑或其他操作会导致问题再次发生-但每次,解决方案都是一样的.关闭所有内容,编译,然后重新打开我需要编辑的内容.)

What I had to do was save them, close them out of the editor, and then compile the project. The project WOULD compile correctly once I'd done that, and after it had compiled, it wouldn't report those errors again even once the pages were opened for editing (though eventually, some edit or other would cause the problem to reoccur -- but each time, the solution was the same. Close everything out, compile, and then reopen whatever I need to edit.)

这篇关于'var_name' 未声明.由于其保护级别,它可能无法访问.在调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆