You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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     = "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;";

        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('&lt;'))
            {
                //parser.Pin(html.Pin.Both);
                parser.Next('&gt;');
                token = watch_token = parser.Token;
                parser.Pin(html.Pin.Both);
            }
        }
    }
}

内容的提问来源于stack exchange,提问作者Willem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 23:45:37