Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The namespace 'Resources' already contains a definition for 'SiteResources'

Tags:

c#

.net

asp.net

Ok I have a issue with my resx files for some reason I have this error

The namespace 'Resources' already contains a definition for 'SiteResources'

all files are within App_GlobalResources but I keep getting this error

any pointers

like image 549
Mich Avatar asked Jul 31 '14 08:07

Mich


4 Answers

There is the likelihood even if you have them hidden in Visual Studio that it’s trying to read a file which is similarly named,

If within GlobalResources you have more than 1 file try renaming the extension like this

From:

SiteResources-fr-FR.resx

To:

SiteResources-fr-Fr.old.resx
(this might still be read)

try changing the extension of the latter so that its complete not a resx file like:

SiteResources-fr-Fr.old

this will 100% not be a resx file now and should stop asp.net confusing the file you wish to use.

Hope this will solve your problems.

like image 132
AlanMorton2.0 Avatar answered Nov 04 '22 01:11

AlanMorton2.0


I ran into that problem when I added a new custom culture on my App_GlobalResources folder but forgot to register it. So I had to remove the file, add the following function in global.asax, browse a random page of my web site so the code gets to run, and finally copy the file back into its folder.

public static void CreateCulture(string name, string cultureInfo, string regionInfo)
{
    try {
        CultureAndRegionInfoBuilder.Unregister(name);
    } catch { }
    var cib = new CultureAndRegionInfoBuilder(name, CultureAndRegionModifiers.None);
    cib.LoadDataFromCultureInfo(new CultureInfo(cultureInfo));  // Populate the new CultureAndRegionInfoBuilder object with culture information.
    cib.LoadDataFromRegionInfo(new RegionInfo(regionInfo));   // Populate the new CultureAndRegionInfoBuilder object with region information.
    cib.Register();
}

In Application_Start:

CreateCulture("en-gb-custom", "en-gb", "gb")

Bonus: don't forget to add full permissions to user IIS_IUSRS on the following folders or the custom language will fail its registration:

  • Folder C:\Windows\Globalization
  • Registry: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Nls\CustomLocale
like image 41
Johann Avatar answered Nov 04 '22 00:11

Johann


This may be a bit of an edge case, but we've run across this in our development environment from time to time. We had to setup a custom culture in Windows to support en-HK. Windows 8.1 now supports this culture natively as does Windows 2012 R2, but older machines need to have the culture created. Any machine that does not have this culture setup will get this error reported. The solution is to create the culture on the machine (We have a console app created for this purpose) and everything starts working again.

I reported this answer also on How to fix "namespace x already contains a definition for x" error? Happened after converting to VS2010

like image 1
P Walker Avatar answered Nov 04 '22 01:11

P Walker


I had a some problem.You should write the resources file exactly like that en-US or any country you can check from this https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx I mean you cannot change the string type like this en-Us or US-en because it is special strign. I hope that is helpfull for everyone

like image 1
Emre Hamurcu Avatar answered Nov 04 '22 02:11

Emre Hamurcu