Resource files naming gotcha in SharePoint

Hi, everyone!

Just have come across another gotcha in SharePoint (though it appears also in pure ASP.NET) – related to file naming of resources inside “App_GlobalResource” folder.

I have a project which run-time resources are collected in (let’s say) “Parent.Child.resx” file. This file is deployed to “App_GlobalResources” folder of Web Application. Recently I have added rather independent part to the solution. The textual resources of this part are externalized into “Parent.Child.Subchild.resx” file. This RESX file is also deployed to “App_GlobalResources”folder.

Once I deployed component’s resource file, SharePoint stopped working and following exception was thrown:

The first marked text was ‘Resources.Parent’ and the second (grey-filled one) was “Child” – so the full text says:

“Compiler Error Message: CS0101: The namespace ‘Resources.Parent’ already contains a definition for ‘Child’”.

I tested the problem on MOSS 2007, SharePoint 2010 and Web Site created in pure ASP.NET 4.0 – the problem appeared everywhere when I uploaded “Parent.Child.resx” together with”Parent.Child.Subchild.resx” files into “App_GlobalResources” folder.

The textual description was rather cryptic, but Visual Studio helped a lot – it showed source C# files generated from RESX files.

So, the first resource file (“Parent.Child.resx”) compiles into following code:

And the second file (“Parent.Child.Subchild.resx”) compiles into following code:

So now everything became clear – in “Resource.Parent” namespace, there are:

  • “Child” class, created from  Parent.Child.resx file
  • “Child” sub-namespace (which is the first part of “Resources.Parent.Child” namespace), created from Parent.Child.Subchild.resx file.

The compiler is not happy about it and throws an exception.

To summarize – don’t create resource files which names are just the prefix of the names of other resource files.

Hope, it helps.

Advertisement

About vtimashkov

.NET, ASP.NET, SharePoint/MOSS developer
This entry was posted in Ideas for projects. Bookmark the permalink.

One Response to Resource files naming gotcha in SharePoint

  1. Pingback: Resource probing during provisioning | Vladimir Timashkov's blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s