Why does Entity Framework return null List instead of empty ones?

You should have your entity create those lists in the constructor. EF doesn’t create dependent collections, and expects the entity to do so. So, your case, you would make your entity like this: class MyClass{ public List<OtherClass> _otherClasses {get;set;} public MyClass() { _otherClasses = new List<OtherClass>(); } }

C# Error with null-conditional operator and await

You can add ?? Operator so if ?. returns null task use CompletedTask instead. await (this.MyObject?.MyMethod() ?? Task.CompletedTask) I would’ve expected that the call to “MyMethod” would simply not be made if “MyObject” is null. Thats true. the ?. operator returns null task instead of calling MyMethod. the null reference exception is made because you … Read more

Why is [Owin] throwing a null exception on new project?

Similar to Sandeep’s answer, I also updated the cookie authentication provider. Except, instead of swallowing the error I threw the exception so you could see what the underlying problem was: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”), Provider = new CookieAuthenticationProvider { // Enables the application to validate the security stamp when … Read more