views:

12

answers:

1

I have written a VERY simple MVC application which just displays a single string from a Resource file. It works just fine on my local machine but when I deploy the project to the web server I get the error.

CS0103: The name 'Resources' does not exist in the current context

You can very easily replicate exactly what I am doing in just 10 steps!

  1. Create a New MVC 2 Web Application.
    (File->New->Project->ASP.NET MVC 2 Web Application, say no to the Unit Testing Project)

  2. Add the "App_GlobalResources" folder.
    (right click the project and select Add->Add ASP.NET Folder->App_GlobalResources)

  3. Add a Resource File to this folder.
    (right click the folder and select Add->New Item...->Resources File. Name it Strings.resx)

  4. Add a single string to the Resource table.
    (Name = "HelloWorld", Value = "I localized Hello World!")

  5. Set the File Properties for the Resource File.
    (Click the file Strings.resx and int the Properties window set Build Action = "Embedded Resource" and the CustomTool = "PublicResXFileCodeGenerator")

  6. Add a new Controller
    (Right click the Controllers folder and select Add->Controller... Name it HelloWorldController.cs)

  7. Add a the View
    (With the cursor in the Index method of the HelloWorldController.cs Press CTRL-M-V. Use the default values including View name = "Index")

  8. Modify the View so that it displays our string from the resource file.
    Replace the content of the MainContent placeholder with

    <h2><%: Resources.Strings.HelloWorld %></h2>
    
  9. Run it locally to test that it works. Which it should.

  10. Publish it to a web server and visit the url "http://localhost/HelloWorld"

This is where I see the error described at the top.

I would imagine that the settings I've put on the ResX file are incorrect and the resource is not published to the server.

Help is greatly appreciated.

Thanks!

+1  A: 

Ah ha! Figured it out. In LARGE part to this article:
http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

Sounds like the App_GlobalResources folder is NOT cooperative with MVC. So I moved my ResX file to a new folder
~/Resources/Strings/Strings.resx

This along with 1 minor change to set the File Property
Custom Tool Namespace = Resources

and Problem Solved!

Justin