Include File References Patch Issue

January 18, 2013

*Update 2

I also found that there was an issue with the <using> statements as well that required an attribute to be added. When I opened the Configure-Assign (Insert Options) or tried to add from template, I would get the following exception:

The type or namespace name 'EventArgs' could not be found.

Once I added an arbitrary attribute to the <using> tag it was fine.

*Update 1

So Sitecore Support got back to me pretty quickly and told me that if I just add an attribute that makes the reference unique that's how to solve the issue. Here's the relevant code:

<?xml version="1.0"?><configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">	<sitecore>		<ui>			<references>				<reference comment="MyLibrary">/bin/MyLibrary.dll</reference>			</references>		</ui>	</sitecore></configuration>

The system I manage was originally built on Sitecore 5.3 and not all the latest and greatest methodologies are being used so when I have time I try to update the system. This time, while working to migrate all the customizations to the web.config to an include file I ran into a slight snag. My longtime friend and confidant, the ever charming System Exception or collegially known as the Yellow Screen of Death:

The type 'System.ComponentModel.IComponent' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Usually they're not too difficult to root out but this one really confused me. I mean who doesn't have the 'System' library referenced. I'm pretty sure it's included by default. Anyway after finding nothing useful on google I was left to my only option. Go back to the original web.config and move the changes over line by line until I hit the issue.

Sure enough the issue resided with the <references> section. Now looking back I guess I should've guessed this would be the problem but hindsite, well, it just is what it is. I checked the rendered config on the show config page [/sitecore/admin/showconfig.aspx] and found that my inserted reference was showing up before the System.dll reference. Ah, that's the issue. It's not being included in the right order. Okay so I just need to put it last and I'll be fine.

Now typically when you patch config something you're telling it to insert before or after something but in this case there are no attributes to use to tell it where to insert. I know I read that I could tell it what position to insert into by giving it the position. It's not optimal but let's just see. To my chagrin, this didn't work. I checked the rendered config on the show config page again and it was showing up correctly but it was still throwing the error. Ok, so let's try and add an attribute like I've seen on John West's blog and insert it after that item using the attribute query. It was rendered right but still throwing the error.

With my options running out my only remaining choice was to just put it back into the web.config. Not what I wanted to do but it did work. For the time being I'll be adding a ticket to the support site to make sure Sitecore knows about it. Who knows maybe it's already a known issue.