I just learned how to register scripts properly in wordpress. Learn something new every day! loving the elimination of duplicates! 1 hr ago
  • Date
  • Friday, March 7, 2008
  • Author
  • Corey Dutson

Cannot insert the value NULL into column Name, Thanks SharePoint

I tried to create a Custom List. I had event receivers attached to custom lists and i got this:
Cannot insert the value NULL into column ‘Name’, table ‘[somesharepointcontentdatabase].dbo.EventReceivers’;
column does not allow nulls. INSERT fails.
The state­ment has been terminated.

I found out what this means and how to get around it.

My fea­ture code was throw­ing an error today. For those who don’t know what I’m talk­ing about here is a crash course: A fea­ture basi­cally allows you to attach func­tion­al­ity to some­thing in Share­Point. Maybe you want to add a menu option to the ‘Site Actions’ menu, or import some files into libraries. In my case I wanted to attach func­tion­al­ity to a spe­cific list. I wrote my fea­ture code, and it seemed fine. Deployed and acti­vated just great.

Then I tried to create a Custom List. I had event receivers attached to custom lists (ListTemplateID=100 for those who care) and i got this:

Cannot insert the value NULL into column ‘Name’, table ‘[somesharepointcontentdatabase].dbo.EventReceivers’;
column does not allow nulls. INSERT fails.
The state­ment has been ter­mi­nated.

Took me a good two hours of trying every­thing I could think of with my XML and code, only to be repeat­edly thwarted by this database-​level error! I tried com­ment­ing out dif­fer­ent sec­tions of my receivers and still got the error. When I com­mented the entire <Receivers> sec­tion, things ran fine, but not the <Receiver> items inside. What the hell is going on? Read on!

I’ll give an exam­ple of what I’m talk­ing about here - the fol­low­ing comes from MSDN:

feature.xml:
<Fea­ture
Scope=”Web”
Title=”Simple Updat­ing Item Event Han­dler Registration”
Id=”A6B8687A-3200-4b01-AD76-09E8D163FB9A”
xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Ele­ment­Man­i­fests>
<Ele­ment­Man­i­fest Location=”elements.xml”/>
</Ele­ment­Man­i­fests>
</Fea­ture>

inside the feature.xml file (above) it ref­er­ences the fol­low­ing file:

elements.xml:

<Ele­ments xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Receivers
ListTemplateOwner=”ADDABAAA-1111-2222-3333-111111111111″
ListTemplateId=”104″>
<Receiver>
<Name>Sim­ple­Up­da­teEvent</Name>
<Type>ItemUp­dat­ing</Type>
<Sequen­ceNum­ber>10000</SequenceNumber>
<Assem­bly>Sim­ple­Up­da­teEven­tHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=10b23036c9b36d6d</Assem­bly>
<Class>MS.Samples.SimpleItemUpdateHandler</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
</Receivers>
</Ele­ments>

This works fine. Here’s some­thing inter­est­ing though: any com­ments - <!– Like this> - you have in the <Receivers> node will be lit­er­ally inter­preted as <Receiver> nodes! That means when­ever it tries to attach event receivers to any list, it treats the com­ments as actual receivers! That’s right, for what­ever reason, the code that ties event receivers to lists lit­er­ally loops through every node (com­ments are still con­sid­ered nodes!) and tries to use them instead of using any sort of XPath. How hard is it to use “//Elements/Receivers/Receiver” as your node col­lec­tion XPath? I really hope who­ever wrote that code got the ruler or something.

The solution: Remove comments from your Feature xml file(s).

I say this because God only knows where else this is hap­pen­ing, and the odds of you real­iz­ing that it is some­thing that should just work, like com­ments, are prob­a­bly not that high. Remem­ber folks, some­times the most obtuse prob­lems have the most simple answers. Try not to over-​think things.

A huge thank you must go out to Janne Mat­tila for being the first (and appar­ently only accord­ing to Google) doc­u­ment­ing this. I wish I had looked sooner.

Design Float Mixx Digg reddit del.icio.us StumbleUpon

Keep it clean, no spam, and thanks a bunch for any feedback you give.

*

*

*

  • Name
  • russell
  • Date
  • Thursday, November 20, 2008
  • Website

Same with the ele­ments file. Man I was bang­ing my head on this one until I found this post. Thank yoouuu

Really? Wow. I still find it hilar­i­ous that instead of pars­ing it with a normal XML parser, they obvi­ously have some custom rigged-​up thing to read through the files. On top of that, the rigged up thing can’t handle com­ments!

Good to know about the ele­ments file!

Maybe it’s just a safe bet to remove com­ments from all the xml files for any­thing like that (fea­tures, site def­i­n­i­tions, etc)