I am using VS2019 and has enabled nullable check semantics in project setting. I am trying to get the executable's path using assembly as below:
var assembly = Assembly.GetEntryAssembly();
if (assembly == null)
{
throw new Exception("cannot find exe assembly");
}
var location = new Uri(assembly.GetName().CodeBase);//doesn't compile.
It says, "assembly" is a [Assembly?] type, while the Uri ctor requires a string, compilation error is:
error CS8602: Dereference of a possibly null reference.
How to fix my code to make it compile? Thanks a lot.