Alexey Andrushkevich Alexey Andrushkevich - 1 month ago 25
C# Question

NotNull attribute

I'm looking at asp.net vnext engineering guideline and have noticed that they recommend to use

NotNull
attribute instead of explicit checking of input argument for null and throwing
ArgumentNullException
. The thing that confused me is that base on this guideline it is just enough to declare this attribute and the checking code will be generated at compile time into the method body. I've tried to do this in my test project however the magic didn't happen i.e. it threw the exception
System.NullReferenceException
instead of
System.ArgumentNullException
. How this is supposed to work? Are they going to use some AOP library to inject the checking code at compile time?

Answer Source

Updated: Jan 12, 2016

The NotNullAttribute is gone. The ASP.NET team removed it and currently there's no plan to bring it back.


The attribute will be replaced through a precompilation step, using Roslyn, by code that does the actual check.

However, the feature is not yet ready. It will come in a later version.