I have a simple program:
class Program
{
static void Main(string[] args)
{
Run().Wait();
}
private static async Task Run()
{
string someVariable = null;
someVariable.Replace(",", ".");
}
}
Run() method is intentionally designed to throw NullReferenceException. What bothers me is why exception is thrown on the line
Run.Wait()
instead of on
someVariable.Replace(",",".");
The actuall exception is available in InnerException - why is that? I lose debugging context, because exception is thrown outside of Run method.
If my program is synchronous:
class Program
{
static void Main(string[] args)
{
Run();
}
private static void Run()
{
string someVariable = null;
someVariable.Replace(",", ".");
}
}
exception is thrown on the correct line. Why async breaks this?