title: How do I write [DefaultValue(null)] in VB.NET? <DefaultValue(Nothing)> does not compile
body: <p>This isn't as trivial as it appears to be. It's a follow-up to <a href="https://stackoverflow.com/q/23266178/240733">this question</a>.</p>
  
  <p>Let's say I have a Windows Forms user control with a property:</p>
  
  <pre class="lang-cs prettyprint-override"><code>// using System.ComponentModel;
  
  [DefaultValue(null)]
  public object DataSource { … }
  </code></pre>
  
  <p>If I translate this to VB.NET, I would try this:</p>
  
  <pre class="lang-vb prettyprint-override"><code>'Imports System.ComponentModel
  
  &lt;DefaultValue(Nothing)&gt;
  Public Property DataSource As Object
      …
  End Property
  </code></pre>
  
  <p>This won't work because the compiler has problems choosing the correct <a href="https://msdn.microsoft.com/en-us/library/System.ComponentModel.DefaultValueAttribute.DefaultValueAttribute.aspx" rel="nofollow noreferrer" title="MSDN reference page">overload of <code>DefaultValueAttribute</code>'s constructor</a>:</p>
  
  <blockquote>
    <p>Overload resolution failed because no accessible <code>New</code> is most specific for these arguments:</p>
    
    <ul>
    <li><code>Public Sub New(value As Boolean)</code>: Not most specific.</li>
    <li><code>Public Sub New(value As Byte)</code>: Not most specific.</li>
    <li><code>Public Sub New(value As Char)</code>: Not most specific.</li>
    </ul>
  </blockquote>
  
  <p>I am quite certain this is because <code>Nothing</code> in VB.NET not only means "the null reference" (<code>null</code> in C#), but also "the default value for" the parameter type (<code>default(T)</code> in C#). Because of this ambiguity, every constructor overload is a potential match.</p>
  
  <p><code>&lt;DefaultValue(CObj(Nothing))&gt;</code> also won't work because it is not a constant value.</p>
  
  <p>How exactly <em>do</em> I write this in VB.NET?</p>
  
  <p><strong>P.S.:</strong> <code>&lt;DefaultValue(GetType(Object), Nothing)&gt;</code> is an option, but it circumvents the problem. I'm really interested if there's any way to use the same constructor for <code>DefaultValueAttribute</code> as the C# version does.</p>