VS2022更新后调试监视窗口报CS0103错误,排查代码诱因
VS2022更新后调试监视窗口异常问题排查
更新VS2022后,调试时查看监视窗口出现CS0103: The name '' does not exists in the current context错误。已按建议提交代码排除自身代码问题,准备上报Bug。
测试场景及结果
所有测试项目均采用默认配置:
- 新建解决方案,添加Windows窗体应用和Windows控件库,创建带值的类,未出现异常;
- 新建解决方案,将StringParser代码放入控件库,并添加Form1构造函数的相关代码,出现上述监视窗口错误;
- 新建解决方案,仅在Windows窗体应用中包含StringParser类,同样出现相同错误。
相关代码
库文件 - StringParser.cs
namespace html { public enum Pin { Start, End, Both, } public class StringParser { private string content = ""; public string Content { get { return content; } set { if (content != value) content = value; if (content.Length > 0) { position = start = 0; end = 0; } } } private int position = -1; private int start = -1; private int end = -1; public bool Next() { ++position; if (position > content.Length) position = content.Length; if (position > end) end = position; return (position >= content.Length); } public bool Next(char to_char, bool include = true) { while (position < content.Length && content[position] != to_char) { ++position; if (position > end) end = position; } if (include) ++position; if (position > content.Length) position = content.Length; if (position > end) end = position; return (position >= content.Length); } public bool Previous() { --position; if (position < 0) position = 0; if (position < start) start = position; return (position ==0); } public string Token { get { return start >= 0 && end <= content.Length && end > start ? content.Substring(start, end - start) : ""; } } public void Pin(Pin pin) { if (pin == html.Pin.Start || pin == html.Pin.Both) start = position; if (pin == html.Pin.End || pin == html.Pin.Both) end = position; } public override string ToString() { if (content == null || content == "") return ""; string s = content.Substring(0, start); string t = Token; string e = content.Substring(end, content.Length - end); if (s.Length > 15) s = "..." + s.Substring(s.Length - 15); if (e.Length > 15) e = e.Substring(0, 15) + "..."; return string.Format("[{0}-{1}-{2}] {3} |-->'{4}' <--| {5}", start, position, end, s, t, e); } } }
窗体应用 - Form1.cs 代码
using System.Windows.Forms; using html; namespace contentdownloader { public partial class Form1 : Form { string filecontent = "<html><head></head><body></body></html>"; StringParser watch_parser = null; string watch_token = null; public Form1() { InitializeComponent(); StringParser parser = new StringParser(); watch_parser = parser; parser.Content = filecontent; string token = ""; while (!parser.Next('<')) { //parser.Pin(html.Pin.Both); parser.Next('>'); token = watch_token = parser.Token; parser.Pin(html.Pin.Both); } } } }
内容的提问来源于stack exchange,提问作者Willem
相关产品推荐
相关产品推荐

