I picked up a bug today where we got a NullReferenceException. I thought this was a good scenario where I could ask GitHub Copilot to find and fix the issue for me.
Here is the orignal code containing the issue:
I asked Copilot to investigate and fix the issue using the /fix slash command;
/fix This code returns a NullReferenceException in some situations. Can you investigate an issue and suggest a solution?
GitHub Copilot was successful in identifying the root cause of the problem. I was passing a ConnectionName using a different casing as the key found in the dictionary (e.g. Northwind
vs northwind
).
That’s good.
However then I noticed the solution it suggested:
Although that is a workable solution that certainly fixes the issue, it is certainly not the simplest and most performant solution. I undid the changes done by Copilot and updated the Dictionary construction instead:
The human in the loop is still required...
More information
Tips & Tricks for GitHub Copilot Chat in Visual Studio - Visual Studio (Windows) | Microsoft Learn