Mich
Mich

Reputation: 151

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

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

Upvotes: 5

Views: 13195

Answers (7)

Emre Hamurcu
Emre Hamurcu

Reputation: 111

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

Upvotes: 1

Abdul
Abdul

Reputation: 2120

Make sure that the culture name you are using is a valid culture name.

For example : sys.pt-eb

The pt-eb is not valid culture name so it will throw an error while building the application.

Supported cultures can be checked from

IE-Browser -> Tools -> Internet Options -> Languages -> Add Languages

Upvotes: 0

Johann
Johann

Reputation: 12398

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

Upvotes: 2

Cosmin
Cosmin

Reputation: 2385

I needed to have resources for different languages. One of them had an incorrect name. Check this page for the correct names of cultures: https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx

Sample names:

  • SiteResources.resx - default resources
  • SiteResources.af-AZ.resx - resources for Afrikaans - South Africa

Upvotes: 0

P Walker
P Walker

Reputation: 592

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

Upvotes: 1

Neel
Neel

Reputation: 11721

Make sure that there is only one GlobalResources.resx file.

try to rename GlobalResources.Portal-0.resx to GlobalResources.Portal-0.old so it is not a resx file now.

Upvotes: 0

AlanMorton2.0
AlanMorton2.0

Reputation: 1053

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.

Upvotes: 6

Related Questions