vb.net – ‘var_name’未声明.由于其保护等级可能无法访问.“在调试模式下

前端之家收集整理的这篇文章主要介绍了vb.net – ‘var_name’未声明.由于其保护等级可能无法访问.“在调试模式下前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这种行为在vb.net Web应用程序解决方案中,该应用程序具有由Web应用程序引用的多个类库项目.

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

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

在手表和即时窗口.

mouse_over智能感知在这些局部变量上不起作用.

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

传入子/功能的所有变量均可访问.在类级别定义的变量也可以访问.

这个行为是多年来在解决方案中的代码中的新特性.子程序和功能的范围没有变化(它们是公共的).

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

我已经尝试过的事情

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

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

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

VS2010中没有出现这种情况.

下面是一个方法和本地变量声明的示例,发生此行为.
如果您遍历声明并设置监视任何本地变量或使用局部变量的任何语句,您将看到

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

作为手表/快速手表/即时窗口中变量的值

Utility1.vb

  1. Imports System.Web
  2.  
  3. Imports System.Text
  4.  
  5. Imports SPBO
  6.  
  7. Public Class Utility1
  8.  
  9. Public oNav_inc As New Navigation_INC
  10. '===========================================================================
  11. 'Utility1.vb
  12. '===========================================================================
  13. Public Sub UTIL_EstablishActivityContext(ByRef Response As HttpResponse,ByRef page As Page,ByRef oGlobal_inc As GlobalVariables_INC)
  14.  
  15. Dim oActivity As ENC2.Web.ActivityContext
  16. Dim oMHardUBO As MHUBO
  17. Dim oPUBO As PUBO
  18. Dim asGroup As String = ""
  19. Dim sGroup As String = ""
  20. Dim bActive As Boolean
  21. Dim g_oUserAccountBO As UserAccountBO
  22. Dim sImplementation As String = ""
  23. Dim rs As DataSet
  24. Dim sQuery As String
  25. Dim rsUser As DataSet
  26. Dim sUserGroups As Object
  27. Dim iLoop As Integer
  28. Dim bInternal As Boolean
  29. Dim g_bInternalUser As Boolean
  30.  
  31. g_bInternalUser = False
  32.  
  33. 'rest of code
  34.  
  35. End Sub
  36.  
  37. End Class

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

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

我要做的是保存它们,将其从编辑器中关闭,然后编译项目.一旦我完成了这个项目,该项目将会正确编译,编译之后,即使一旦打开编辑页面,它也不会再报告错误(尽管最终有些编辑或其他问题会导致问题重新出现)但每次解决方案是一样的,关闭所有内容,编译,然后重新打开任何我需要编辑的内容.)

猜你在找的VB相关文章