Problem after updating VS2022 viewing the watches. After an answer with proposal to post the code, I do so to exclude the problem is caused by my code prior to reporting a bug.
The original question: Watch window at debugging: CS0103: The name '' does not exists in the current context. Version and solution specifics are stated there.
The code is merely to get something on screen.
Things I tried afterwards:
- Creating a new solution, adding a windows form app and windows controll library. Created a class with values.
No problem here,
- Doing the same but, also a new solution, pasted the code of
StringParser
into the library and the relevant code of the constructor ofForm1
, - Again a new solution where the
StringParser
is part of only a windows forms app,
Both the same problem.
The image contains a screenshot of the watch window. Also from the code file to show debugging state. (The code is as formatted text below).
All projects are 'out-of-the-box'
Library - StrangParser.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);
}
}
}
Form App - Form1.cs - code
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);
}
}
}
}