Rya*_*ohn 1 .net t4 visual-studio
我试图使用T4 Text Templating生成代码,但在运行脚本时,我收到以下错误:
Running transformation: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.VisualStudio.TextTemplatingB0A58A4C85EA3D7032675015C6052C89.GeneratedTextTransformation.TransformText() at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)
由于我不熟悉T4,我不确定在哪里寻找解决此问题的方法.
您需要调试模板以查找NullReferenceException发生的位置.蒂姆·拉尔森具有快速浏览这里和Oleg Sych发表有更多的细节在这里,与T4他的其他优秀的博客条目一起.
这是短短版本:
<#@ template debug="true" #>System.Diagnostics.Debugger.Launch();System.Diagnostics.Debugger.Break();这是一个简单的例子来帮助捕获NullReferenceException在bar上调用ToString时:
<#@ template debug="true" language="C#" #>
<#@ output extension=".txt" #>
<#
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
object bar = null;
#>
foo<#= bar.ToString() #>
Run Code Online (Sandbox Code Playgroud)
一定要检查第一个链接,虽然因为一些版本中,你将需要更新注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgJITDebugLaunchSetting来0x2把事情向正确的行为.
| 归档时间: |
|
| 查看次数: |
4569 次 |
| 最近记录: |