You type “it doesn’t work, help” into a forum, paste a blurry screenshot, and wait. A day goes by and nobody answers. People aren’t being rude. There is just nothing to answer: nobody knows what you were trying to do, what you saw, or what you already tried.
Asking for help well is a skill, and you learn it the same way you learned for or switch. In this chapter you’ll see what to do before you ask, how to shrink your problem to the essentials, what to put in the question, and how to close the loop when someone answers.
Before you ask, search the exact error
Most errors you’ll hit were already hit by someone else. Your job is to search for them properly.
Copy the error message exactly as it appears in the terminal, without your file paths or your variable names, and paste it into a search engine. For example:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary
With that line alone, the first result usually has an explanation. Two details help:
Search in English. .NET messages are in English and so are most of the answers. If your system shows errors in another language, search the English text.
Remove what’s yours. CS0029 and KeyNotFoundException help anyone. Your variable name cornerStoreInventory only helps you, and leaving it in the search pushes the good results away.
If you’re still stuck after twenty or thirty minutes, it’s time to ask. There’s no magic number, but spending three hours on the same thing isn’t useful either. What is useful is arriving at the question after doing what chapter 7 taught: read the full error, go to the line the stack trace points at, and look at the values with the debugger.
The minimal example
Your real program has a hundred lines. The problem almost certainly lives in three of them. A minimal reproducible example is the smallest program that still shows the same error, and building one is the best part of asking for help for a practical reason: many times, while you shrink the code, you find the bug yourself.
The method is to remove things until the error disappears, then put back the last thing you removed. Concretely:
- Copy your project to a new folder, or create one with
dotnet new console -n Example. - Delete everything unrelated to the error: menus, other methods, console input.
- Replace real data with short, made-up data.
- Run it. If the error is still there, delete more. If it disappeared, put back the last thing you removed.
Say your corner store program has an inventory and fails when it looks up a product. Instead of pasting a hundred lines, you leave this:
var inventory = new Dictionary<string, int>();
inventory["Rice"] = 10;
Console.WriteLine(inventory["rice"]);
Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'rice' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Program.<Main>$(String[] args) in .../Program.cs:line 3
Three lines anyone can copy, paste, and run. When someone can reproduce your error in a minute, answering you is easy. And if you look at it calmly, you may already have spotted the difference between "Rice" and "rice". That happens a lot.
What to include in the question
A good question has five parts. Use them as a template.
1. What you’re trying to do. One or two sentences about the goal, not just the error. Sometimes the best answer is “don’t do it that way, do it this other way,” and that is only possible if people know what you’re after.
2. The minimal code. The example from the previous step, as text inside a code block. Not a screenshot: nobody can copy and run an image.
3. The full error. The whole message, also as text. Include the exception type, the message, and the stack trace lines.
4. What you expected and what happened. “I expected it to print 10 and I got an exception.”
5. What you already tried. This saves time for whoever helps you and shows you’re not asking someone to do your homework. “I searched the error, saw the key doesn’t exist, and checked that I stored ‘Rice’ in the dictionary.”
It’s also worth giving the environment: your .NET version (dotnet --version), your operating system, and your editor. It doesn’t always matter, but when it does, it’s the first thing you’ll be asked.
Put together, it looks like this:
Title: KeyNotFoundException when looking up "rice" in a Dictionary<string, int>
I'm building an inventory for a corner store as a console app.
I store products in a Dictionary<string, int> (name, quantity).
I reduced my program to this:
var inventory = new Dictionary<string, int>();
inventory["Rice"] = 10;
Console.WriteLine(inventory["rice"]);
I expected it to print 10. I get:
Unhandled exception. System.Collections.Generic.KeyNotFoundException:
The given key 'rice' was not present in the dictionary.
I searched the error and understand the key doesn't exist, but I don't
see why, since I added "Rice". Using .NET 10 on macOS with VS Code.
Look at the title: it names the error and what triggers it. “Help with C#” tells nobody anything.
Where to ask
Communities. A small group where people already know each other is usually the best place to start. In the BoricuaCoder Discord community you can ask using the template above.
Stack Overflow. A technical question-and-answer site with strict rules. Before you ask, search well: your question probably has an answer already. If you do ask, make it specific and include the minimal example. Vague questions get closed fast, which discourages many beginners. Don’t take it personally, it’s the site’s filter.
A project’s issues. If the problem seems to be in a package or library that isn’t yours, the place is the project’s GitHub repository, in the Issues tab. Read the README first and check whether someone already reported the same thing.
Someone you know. A classmate, a coworker, a friend who codes. Explaining the problem out loud, as we discussed in chapter 7, often solves it before you finish the sentence.
How to treat the person helping you
Whoever answers is giving you their time. A few simple habits make the difference:
Answer their questions quickly. If they ask for your .NET version or the full code, send it.
Try what they suggest before replying, and say what happened, even if it failed. “I tried TryGetValue and now I get a different error” is useful information.
Don’t ask the same question in five places at once. If you do, say so in each one. Otherwise several people may spend time answering something already solved.
Close the loop. When it works, say so and explain what the fix was. On Stack Overflow you mark the answer as accepted, and in a chat it’s enough to write “that was it, thanks, the difference was upper vs lower case.” It helps the person who helped you, who sees it was worth it, and whoever lands on the same error a year from now.
Exercise: fix this question
Here is a question of the kind you see all the time:
Hi, my program doesn't run, I get a red error. Help please!!
And this is the code behind it:
var inventory = new Dictionary<string, int>();
inventory["Rice"] = 10;
Console.WriteLine(inventory["rice"]);
Write a better version of the question using the five parts: goal, minimal code, full error, what you expected, and what you tried. Then run the code on your machine to get the real error message.
Suggested solution
It would look like the template above. What matters is that your version has a title that names KeyNotFoundException, the code as text, the full message copied from your terminal, what you expected (printing 10), and what you already tried. If while writing it you noticed that "Rice" and "rice" are different keys, you solved it without asking anyone. That’s part of the exercise too.
One way to fix the program is to look up with the same casing you stored, or to create the dictionary ignoring case:
var inventory = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
inventory["Rice"] = 10;
Console.WriteLine(inventory["rice"]);
10
Recap
- Before asking, search the exact error message, in English and without your own names.
- A minimal reproducible example is the smallest program that still fails. Building it often shows you the bug.
- A good question has the goal, code as text, the full error, what you expected, and what you tried, plus your .NET version and system.
- Where to ask: the Discord community, Stack Overflow, a project’s issues, someone you trust.
- Try what people suggest, report the result, and close the loop when it’s solved.
One chapter left, the last of the path. We talk about artificial intelligence: how to use it to learn faster without skipping the learning.
Have a question waiting?
DM me on Instagram or ask in the Discord community. If you use this chapter’s template, you’ll save all of us a lot of back and forth.
