Cannot insert the value NULL into column ‘Name’, column does not allow nulls.
Yeah, right. This bug just cost me two hours of work, debugging everything from my own code, which of course never fails for any reason, to SQL server.
Here’s the situation. I added an item event receiver as I usually do, using the following elements.xml file:
<Receivers ListTemplateId="10102"> <!-- Nyheter --> <Receiver> <Name>AddingEventHandler</Name> <Type>ItemAdded</Type> <SequenceNumber>10000</SequenceNumber> <Assembly>*</Assembly> <Class>*</Class> <Data></Data> <Filter></Filter> </Receiver> <Receiver> <Name>UpdatedEventHandler</Name> <Type>ItemUpdated</Type> <SequenceNumber>10000</SequenceNumber> <Assembly>*</Assembly> <Class>*</Class> <Data></Data> <Filter></Filter> </Receiver> </Receivers>
Yes, the assembly and class elements have been changed to protect the innocent.
Now, this is fairly straight-forward, right? Suddenly I get the Unknown error when activating the feature. Logs show up the strangest of strange error messages:
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column ‘Name’, table ‘WSS_Content_152a4c9ee1284cd888b3060c5f70779c.dbo.EventReceivers’; column does not allow nulls. INSERT fails.
Hm… I do have a name, so why would this fail?
Turns out, in all its wisdom, SharePoint has decided that the comment tag should be parsed as a receiver element. Remove the comment tag and everything works fine again.
Problem is, I can swear I have done exactly this before. I need to dig through old code to see why it worked then…
Found this article valuable? Want to show your appreciation? Here are some options:
a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.
b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.
c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!