'var_name'未声明.由于其保护级别,它可能无法访问.在调试模式下

use*_*755 12 vb.net visual-studio-debugging visual-studio-2012 visual-studio-2013

此行为位于vb.net Web应用程序解决方案中,其中包含Web应用程序引用的多个类库项目.

代码编译,但在调试模式下,引用的类库中的某些函数/子例程具有显示的局部变量

'var_name'未声明.由于其保护级别,它可能无法访问.

在手表和即时窗口.

mouse_over intellisense对这些局部变量不起作用.

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

传入Sub/Function的所有变量都是可访问的.在类级别定义的变量也是可访问的.

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

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

我已经尝试过的事情:

* 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
Run Code Online (Sandbox Code Playgroud)

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

我有一位同事在TFS中获得相同解决方案的副本,并且他的本地副本中不会发生此行为.

在VS2010中没有发生此行为.


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

'var_name'未声明.由于其保护级别,它可能无法访问.

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

Utility1.vb

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
Run Code Online (Sandbox Code Playgroud)

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

use*_*704 2

几个月前,我在 VS2013 中处理完全相同的问题。这是一个令人发狂的错误,微软(我最后一次看到)无法重现。对我来说,它来了又去,没有明显的原因。最初几次,我通过执行上面您已经尝试过的一些操作来摆脱它。但后来它又回来了,我无法摆脱它。最终的窍门是卸载并删除所有版本的 Visual Studio 的所有痕迹(包括手动扫描注册表),删除所有代码、项目、解决方案等,并删除所有版本的 .NET。

然后我放回.NET,重新安装VS2013,并从TFS获取最新版本。从那以后,它就再也没有回来过。当然希望不会。祝你好运!