For a customer project I had to add a custom tab to the Ribbon of SharePoint 2010 for a specific library. In this tab I wanted to have several groups of controls. In one group I needed to have a button that triggers the standard upload functionality of SharePoint (Command="UploadDocument"). So far this is a pretty straight forward process.
If you've ever created a CustomAction to add a tab to the Ribbon, you'll agree that you've to write a looot of XML. I personally believe it's a best practice to comment the code one creates. If you have a XML-document with hundreds of lines of mark-up, usually it makes sense to add a comment here and there. In my case my CustomAction-XML was commented like this:
…
<Groups
Id="Test.Ribbon.Tab.Groups">
<!--
Group "New" with Button "Upload"
-->
<Group
Id="Test.Ribbon.Tab.NewGroup"
…>
</Groups>
<Controls
Id="Test.Ribbon.Tab.NewGroup.Controls">
<Button
Id="Test.Ribbon.Tab.NewGroup.Controls.Upload"
Command="UploadDocument"
…
/>
</Controls>
</Group>
…
As you can see I've added a comment above the group "Test.Ribbon.Tab.NewGroup" and with this I've entered a world of pain. The Ribbon and the tab including all groups and controls were rendered without any issues. I also was able to click on the button "Test.Ribbon.Tab.NewGroup.Controls.Upload" and the "Upload Document"-dialog was displayed as expected, but after clicking on the "OK"-button in the dialog, I ran into this well-known error:
In the SharePoint log you can find the following entry related to this error:
System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Web.CommandUI.Ribbon.CreateRenderContext(CUIDataSource uiproc) at Microsoft.Web.CommandUI.Ribbon.Render(HtmlTextWriter writer) at Microsoft.SharePoint.WebControls.SPRibbon.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The method "Microsoft.Web.CommandUI.Ribbon.CreateRenderContext" throws a "System.NullReferenceException". Whoa! To make a long story short, after digging around for several hours I found the reason for this issue: the comment above the group in the CustomAction-XML. Here is what Reflector tells you about the implementation of "Microsoft.Web.CommandUI.Ribbon.CreateRenderContext":
…
DataNode node4 = uiproc.GetResultDocument().SelectSingleNode("/spui:CommandUI/spui:Ribbon/spui:Tabs/spui:Tab[@Id='" + this.InitialTabId + "']/spui:Groups");
if (node4 == null)
{
node4 = uiproc.GetResultDocument().SelectSingleNode("/spui:CommandUI/spui:Ribbon/spui:ContextualTabs/spui:ContextualGroup/spui:Tab[@Id='" + this.InitialTabId + "']/spui:Groups");
}
Hashtable hashtable = new Hashtable();
if (node4 != null)
{
foreach (DataNode node5 in node4.ChildNodes)
{
XmlAttribute attribute2 = node5.Attributes["Id"];
if (attribute2 != null)
{
hashtable[attribute2.Value] = node5;
} } }
…
I will not comment on the quality of this implementation, but if you look at XmlAttribute attribute2 = node5.Attributes["Id"]; it becomes clear: the Attributes-property is the reason why I get the NullReferenceException, because for a System.Xml.XmlNode-Object that is a System.Xml.XmlComment this property is null (http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.attributes.aspx). So if you put a comment above your group in your CustomAction-XML you're doomed. Do yourself a favor and don't do it.
I hope this blog-post will save you save some time and headaches. It took me quite some time to figure out the reason why my button in my custom Ribbon-tab wasn't working.
| Created by Sven Häfker |

Da, probabil, de aceea este
Kommentiert von: Insenoenropsy | 06. März 2011 um 11:30 Uhr
The same is true for field definitions in a content type...
Kommentiert von: marco | 25. August 2011 um 07:02 Uhr
Lesen Sie das gesamte Blog, pretty good
Kommentiert von: tauctsace | 28. August 2011 um 17:53 Uhr
Ich mag die wertvollen Informationen, die Sie in Ihrem Artikel. Ich werde bookmark Ihr Blog und überprüfen Sie auch hier wieder regelmäßig. Ich bin mir ziemlich sicher, dass ich viele neue Sachen hier zu lernen! Viel Glück für die nächste!
Kommentiert von: anabolics online | 02. Oktober 2011 um 22:46 Uhr
Im Großen und ich weiß nicht in Blogs posten, aber ich sollte sagen, dass dieses Thema wirklich hat mich gezwungen , dies zu tun . Wirklich schöner Artikel !
Kommentiert von: buy proviron | 18. November 2011 um 06:41 Uhr
Vielen Dank für Ihren Artikel . Was ich sagen will ist, dass bei der Suche nach einem guten auf dem Netz Elektronik-Geschäft , für eine Web-Seite mit umfassenden Informationen über kritische Faktoren wie die Sicherheit und Verlustrechnung, grundlegenden Sicherheits- Details , Zahlungsmodalitäten , zusammen mit anderen Begriffen und auch Politik zu suchen. Normalerweise nehmen Sie sich Zeit , um zu helfen sowie FAQ Bereich schauen, um eine viel bessere Vorstellung von der Art und Weise das Geschäft funktioniert, was sie für Sie durchführen und wie Sie optimale Nutzung der Funktionen machen können.
Kommentiert von: crystal lighting wholesale | 21. November 2011 um 12:48 Uhr
Ich auf jeden Fall erwünscht, um eine schnelle Konzept liefern Ihnen für das nette Tipps und Hinweise Sie auf www.avanadeblog.com Posting bist danken. Meine zeitraubende Internet erscheinen bis jetzt mit hilfreichen Strategien belohnt worden, um mit meiner Familie und Freunden auszutauschen. Ich würde behaupten, dass wir dem Leser dadurch wirklich gesegnet sind, um in ein hilfreiches Community mit unglaublich tolle Menschen mit aufschlussreichen Punkte eingehen. Ich fühle mich wirklich sehr dankbar, entdeckt die Webseite zu bekommen und erscheinen vor, um eine Vielzahl von zusätzlichen unterhaltsame Momente zu lesen hier. Dank viel mehr für ein gutes Geschäft der Dinge.
Kommentiert von: Kaufen Deca Durabolin | 12. Dezember 2011 um 00:03 Uhr
Howdy , ich diese Arbeit apreciated auf dieser Website , sind Sie mit einer spektakulären Dinge beitragen ! Diese Web-Seite ist viel interessanter!
Mein Name ist Helen, ich in Valencia geboren wurde, so werde ich ein Fan von dieser Website , kann Meine Interessen langweilig sein , aber ich werde sie trotzdem sagen, ich liebe Fußball sowie die Fischerei , und ich auch hören viel Radiohead auf meinem roadtrips , ich bin Single jetzt so männliche Nutzer .... einfach flirten mit euch lol:) ! Ich habe bereits versucht Online-Dating ist nicht sehr gut funktioniert ....
Ich schrieb diesen Kommentar , weil wie gesagt vorher Ich mag wirklich diese Website habe ich auch ein Forum genau wie Sie , aber mir ist vielen von diesem geht es darum, No Deposit Bonus ....:)
Ich werde auch zu entschuldigen , indem meine Sprache ist der einzige Weg erhalte ich mit Euch zu sprechen ist ....siehe ya an euch alle , See ya
Kommentiert von: Poker Rules | 15. Dezember 2011 um 07:01 Uhr
Solche informativen Website! Große Dank! Vielen Dank für eine gute Zeit Ihre Website besuchen. Es ist wirklich eine Freude, Verständnis eine Website wie diese mit netten Informationen gefüllt. Vielen Dank!
Kommentiert von: сосна мебель | 22. April 2012 um 02:54 Uhr
Seine Lust zu Ihrem Blog zu verstehen. Die oben genannten Artikel ist ziemlich außergewöhnlich, und ich wirklich genossen lese dein Blog und Punkte, die Sie zum Ausdruck gebracht. Ich mag erscheinen wieder über eine typische Basis post viel mehr in der topic.Thanks für den Austausch von ... weiter schreiben!
Kommentiert von: сосна мебель | 22. April 2012 um 04:01 Uhr
Thank you very much for this hint! I searched about few hours on my project where this f*** NullReferenceException is coming from.. Now I know that this was caused by a comment line above the button definition..
thanks very much again!
Kommentiert von: Fabian | 14. Mai 2012 um 06:47 Uhr
Thank you so much! I've been looking for solutions everywhere in my code and I couldn't figure out why it wasn't working. Thanks to your blog it didn't take me even longer.
Kommentiert von: Dennis | 30. Mai 2012 um 00:19 Uhr
As I tried and test many times, this issue only occurs when you place comments before a node which has "Id" attribute (e.g. Group, FlyoutAnchor, Button, etc.), other nodes without "Id" may not be affected.
Kommentiert von: Serge Wazuki | 13. November 2012 um 01:50 Uhr