1

Every so often, TDS will throw a NullReferenceException while attempting to generate code for sync'ed Sitecore Items.

Here is the error from the output log:

Generating file C:\Path\To\GeneratedCode.cs ERROR : on line 0 column 0 of file C:\Path\To\Code\Generate\Template.tt Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TextTemplating4EBD01F908618B2878D40309BB467CB0AF91462B3C9AA05AF72392556DFEBB765829C5679F118E27F30F9B93397F2511CA0D88F187AE7DFEBE5EEE255C5A7A49.GeneratedTextTransformation.<>c.b__5_2(SitecoreTemplate t) at System.Linq.Enumerable.d__16`2.MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Microsoft.VisualStudio.TextTemplating4EBD01F908618B2878D40309BB467CB0AF91462B3C9AA05AF72392556DFEBB765829C5679F118E27F30F9B93397F2511CA0D88F187AE7DFEBE5EEE255C5A7A49.GeneratedTextTransformation.GetFieldsForTemplate(SitecoreTemplate item, Boolean includeBases)
at Microsoft.VisualStudio.TextTemplating4EBD01F908618B2878D40309BB467CB0AF91462B3C9AA05AF72392556DFEBB765829C5679F118E27F30F9B93397F2511CA0D88F187AE7DFEBE5EEE255C5A7A49.GeneratedTextTransformation.TransformText()

This is an intermittent bug that happens, most commonly, after I get latest from my branch. It resolves itself up after a few computer restarts; however, if there's a way to fully prevent it or to clear a cache somewhere to fix it when it comes up, I would prefer such a solution.

  • Are you changing branches while Visual Studio is open? I have seen issues with that. – Richard Seal Dec 7 '18 at 13:32
  • That tends to be the trigger when this happens, yes. So it feels like a caching issue and am hoping to find where/how to resolve when I forget to close the solution prior to changing branches – JamesEggers Dec 7 '18 at 16:11
1

You must have already solved this issue by now however for those facing this issue, you can follow these steps.

  1. Close Visual Studio (ensure devenv.exe is not present in the Task Manager)
  2. Delete the %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\15.0\ComponentModelCache directory
  3. Restart Visual Studio.

Source: https://github.com/Codealike/Codealike-KnowledgeBase/blob/master/clear-visual-studio-component-cache.md

Took me few hours to try everything and found the above trick fixes the issue.

|improve this answer|||||
0

I have sometimes seen issues where TDS gets out of date (especially when switching between git branches).

I have always been able to resolve them by right-clicking on the TDS project and selecting Re-Generate Code for all Items:

Context menu with regenerate code for all items highlighted

|improve this answer|||||
  • The error I posted occurs when I select Re-Generate Code for all Items – JamesEggers Dec 6 '18 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.