Using jsonStream = New FileStream(appPath, FileMode.Create, FileAccess.Write)
What your code is doing with File.OpenWrite is opening a file with FileMode.OpenOrCreate, which will NOT completely overwrite the content of the file. It will open an existing file AND KEEP THE CONTENT IN IT for write.
Your code is failing because the file you're writing used to be at least one character longer than what you're writing now. When you write the new content of the file, only the bytes up to the Length of the content you're writing are overwritten. The remaining original content of the file remains intact.
Changing the FileMode to Create opens the file, but truncates the content so everything in the existing file is removed. Read up on it here[^].
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
Thank you for answering a question I didn't ask. I asked what type of email server you were going to be pulling it from. How do you plan to connect to the server? Are you going to use POP3? SMTP? IMAP?
The approach you take will be different depending on which connection type you are using. For instance, POP3 isn't going to keep track of unread emails for you.
Your highest priority should be to learn to use the debugger. It might sound advanced... but it isn't. You will be able to spot the course of errors like this in seconds - even without a heap of experience. Sure some errors will still be tricky... but if they are tricky with a debugger, they are pretty much impossible to solve without.
All you have to do is set a break point in the code you see a problem with (F9 in Visual Studio default key binding). Start the program with the debugger attached (F5) and reproduce the problem. Now you can step through the program line by line (F10/F11)- and you can see the values of all variables and fields at each line in the program.
Spotting the setter calling itself is trivial this way. As a beginner you might still want to ask help on how to solve a problem once you identified it - but at least you can ask a much more precise question when you know what the error is - and get help a lot easier.
So please - take the time to learn the debugger. The half hour will come back with interest of a few million percent.
Rule number 2 when troubleshooting (rule number one is "use the debugger") is not to assume anything. Assuming your debugger won't show you what is wrong is not the right approach.
What would happen if you had spend 10 seconds setting a breakpoint in the getter and setter and then kept pressing F11: You would see your code repeatedly call itself, while the callstack keeps growing one line each time it calls itself.
Error messages which tell you about spelling mistakes or other syntax errors are generated at compile time of your program. No executable is produced and therefore your program doesn't run.
A stack overflow condition can only occur when your program has been compiled and started running.
The debugger is the tool to be used for analyzing run time errors.
You should learn to understand the difference between these to error types.