Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to debug your template to find where the <code>NullReferenceException</code> is occurring. Tim Larson has quick overview <a href="http://adventuresindotnet.blogspot.com/2011/11/debugging-t4-templates.html" rel="nofollow noreferrer">here</a> and Oleg Sych has a more details <a href="http://www.olegsych.com/2008/09/t4-tutorial-debugging-code-generation-files/" rel="nofollow noreferrer">here</a>, along with his other excellent blog entries on T4.</p> <p>Here's the short-short version:</p> <ol> <li>Add debug="true" to template directive: <code>&lt;#@ template debug="true" #&gt;</code></li> <li>Launch debugger <code>System.Diagnostics.Debugger.Launch();</code></li> <li>Break <code>System.Diagnostics.Debugger.Break();</code></li> <li>Select <em>New instance of Microsoft Visual Studio</em> in <em>Visual Studio Just-In-Time Debugger</em> dialog and click <em>Yes</em></li> <li>Debug your T4 template</li> </ol> <p>Here is a simple example to help catch the <code>NullReferenceException</code> when calling ToString on bar:</p> <pre><code>&lt;#@ template debug="true" language="C#" #&gt; &lt;#@ output extension=".txt" #&gt; &lt;# System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); object bar = null; #&gt; foo&lt;#= bar.ToString() #&gt; </code></pre> <p>Be sure to check first link though since on some versions you'll need to update the registry key <code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgJITDebugLaunchSetting</code> to <code>0x2</code> to get things to behave correctly.</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.
    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