In NET Core 3.1
How is the return value of Assembly.Load(Assembly) never null? The code hint I receive is that the expression (Assembly.Load(Assembly) != null
) is always true. Is Assembly a reference type?
if (env.IsDevelopment())
{
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
if (appAssembly != null)
{
config.AddUserSecrets(appAssembly, optional: true);
}
}
.NET Core:
That's because of this line in the source code, which effectively tells the compiler this value is not null. See documentation on the static code analysis here.
return retAssembly!;
So you'll get a non-null value or an exception.
.NET Framework:
That's because the source code has a contract:
public static Assembly Load(AssemblyName assemblyRef)
{
Contract.Ensures(Contract.Result<Assembly>() != null);
//More code
}
So you will either get a non-null return value, or an exception.