Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a bug in .NET Framework 4 (and .NET 4.5, <strong>not in .NET 3.0 and .NET 3.5</strong>).</p> <p>Method <code>PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.DetermineWhetherDBNullIsValid(object item)</code> is causing the issue.</p> <p>Looked with .NET Reflector, its code looks like this:</p> <pre><code>private bool DetermineWhetherDBNullIsValid(object item) { PropertyInfo info; PropertyDescriptor descriptor; DependencyProperty property; DynamicPropertyAccessor accessor; this.SetPropertyInfo(this._arySVS[this.Length - 1].info, out info, out descriptor, out property, out accessor); string columnName = (descriptor != null) ? descriptor.Name : ((info != null) ? info.Name : null); object arg = ((columnName == "Item") &amp;&amp; (info != null)) ? this._arySVS[this.Length - 1].args[0] : null; return SystemDataHelper.DetermineWhetherDBNullIsValid(item, columnName, arg); } </code></pre> <p>Issue is in the following line:</p> <pre><code>object arg = ((columnName == "Item") &amp;&amp; (info != null)) ? this._arySVS[this.Length - 1].args[0] : null; </code></pre> <p>Code assumes that if <code>columnName</code> is <code>"Item"</code>, then property is indexer and tries to access its first argument via <code>args[0]</code> and this is where <code>NullReferenceException</code> occurs because <code>args</code> is <code>null</code> since property is not indexer. It just happens to be named <code>"Item"</code>.</p> <p>.NET implementers should have used <a href="http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.getindexparameters.aspx" rel="noreferrer">PropertyInfo.GetIndexParameters()</a> on <code>info</code> and if returned array doesn't contain zero elements, make certain assumption that property is indexer. Or use <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.indexername.aspx" rel="noreferrer">Binding.IndexerName</a> for checking (Binding.IndexerName has value <code>"Item[]"</code>).</p> <p>Why issue arises only in Visual Studio debugger is much more subtle and it is hidden in following method: <strong>PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.DetermineWhetherDBNullIsValid()</strong>.</p> <p>Here is a disassembled code:</p> <pre><code>private void DetermineWhetherDBNullIsValid() { bool flag = false; object item = this.GetItem(this.Length - 1); if ((item != null) &amp;&amp; AssemblyHelper.IsLoaded(UncommonAssembly.System_Data)) { flag = this.DetermineWhetherDBNullIsValid(item); } this._isDBNullValidForUpdate = new bool?(flag); } </code></pre> <p>Since <code>item</code> variable won't be null (it is actually an instance of <a href="http://msdn.microsoft.com/en-us/library/system.weakreference.aspx" rel="noreferrer">WeakReference</a> which holds <code>MainViewModel</code> instance), only condition for which failing method <code>DetermineWhetherDBNullIsValid(item)</code> is called is if System.Data.dll assembly is loaded, which is checked with <code>AssemblyHelper.IsLoaded(UncommonAssembly.System_Data)</code>.</p> <p>Visual Studio debugger will always load System.Data.dll because project is referencing it, although it is not using it. Outside Visual Studio debugger, System.Data.dll gets loaded only if used, which is never, and that is why application doesn't fail outside Visual Studio.</p> <p>You have following options to get rid of this issue:</p> <ol> <li>Rename property which is bound to <code>ComboBox.SelectedItem</code> to some name other than <code>"Item"</code> so that buggy .NET implementation doesn't assume anymore that property is indexer.</li> <li>Remove System.Data.dll from project references so it doesn't get loaded even in Visual Studio debugger.</li> </ol> <p>I find option 2 more fragile, since situation may arise that System.Data.dll must be loaded, either directly by your application or indirectly by some other loaded assembly.</p> <p>So I would go with option 1.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload