我正在使用:
Visual Studio Community 2022 (64-bit), Version 17.4.2
with
.NET Framework, Version 4.8.09032.
昨天,2022 年 2 月 12 日有更新,我是通过“Visual Studio 安装程序”安装的。
此后,我在调试时无法在“观察”窗口中观察局部变量。它给了我一个 CS0103 错误(见下图)。
同样在“本地”窗口中,它们也不会出现。
(edit: 已经贴出代码了StringParser
here 监视窗口 CS0103 - 跟进以排除我的代码问题 https://stackoverflow.com/questions/74694938/watch-window-cs0103-follow-up-to-exclude-my-code-as-problem)
解决方案非常简单,它由两个项目组成:
Windows Forms App (.NET Framework)
Windows Forms Control Library (.NET Framework)
后者当然与第一个相关。控制库包含StringParser
.
基本上,接下来的代码是所有表单项目。这只是创建时的测试代码StringParser
。在更新之前,这工作得很好,就像有parser
作为全球的Form1
.
声明局部变量时parser
并将其实例化为 Form1 的全局,没有CS0103
在那个变量上。
接下来的两个问题解决了这个问题。
VS 2015 Update 2 - 调试时变量不存在,为什么? https://stackoverflow.com/questions/36463286/vs-2015-update-2-variable-does-not-exist-when-debugging-why
在 Visual Studio 2019 中调试大多数变量时出现错误 CS0103 https://stackoverflow.com/questions/58397723/error-cs0103-when-debugging-most-variables-in-visual-studio-2019
虽然我怀疑第一个确实描述了我的情况。尚未尝试该解决方案,因为它是不同的版本。
第二个没有解决这个问题。
public Form1()
{
InitializeComponent();
StringParser parser = new StringParser();
parser.Content = filecontent;
string token = "";
while (!parser.Next('<'))
{
parser.Next('>');
token = parser.Token;
}
}