I have an application that localizes properly in IIS Express but causes an error message after being deployed to the server (IIS 7.5), but only where using expression syntax e.g. <asp:localize id="fooctrl" text="<%$ Resources:SiteResources, Foo_Key %>" runat="server" />
. On my local machine running in IIS Express this works just great. But once deployed to the server this will cause the error:
The resource object with key 'Foo_Key' was not found.
I can set properties to the resource key in the code behind with no issues like so:
fooctrl.Text = SiteResource.Foo_Key;
I can also output the resource string using the literal server side tag or the encoded server side tag with no issues:
<%= SiteResource.Foo_Key %>
<%: SiteResource.Foo_Fey %>
I don't believe it's a deployment issue as it's only the expression syntax that doesn't appear to work. I'd like to understand what I'm doing wrong or what could be causing the deployed behavior? I'd really rather not have to set all my localized properties of server controls in the code behind.
More Information
For sh_ts and gr_ns I copied the App_GlobalResources folder to the server. My errors went away. That made me change my resources build action from Embedded Resource
to Content
so that they would get published with the application. While the folder and resx files did indeed appear on the server after publishing, I received an error: "Could not find any resources appropriate for the specified culture or the neutral culture."
So that leaves me a little confused about the Embedded Resources. What is actually embedded if I need the resource files on the server? If I need to not only embed the resources, how can I get Visual Studio 2012's Publish Web to simultaneously compile the resources and copy the files as if they're content? I can't find any settings to do that.
Even More Information
I moved the resources to an external assembly today to support localizing other supporting assemblies in addition to the web application. I removed the resource files from my web app, added the references to all all applicable projects, updated my references, etc. Everything worked like gangbusters in IIS Express. The web application localized great, the external assemblies localized great but the web app failed to localized when I deployed to IIS 7.5. Same deal as before with the expression syntax. Again deploying the .resx files resolved the error.
I don't understand what the issue is. The resources are correct as far as I can tell and are as follows:
I even used JetBrains dotPeek to decompile the resource assemblies and I can see the embedded XML complete with values in each of them.
In order to use embedded resources in an ASP.NET application using the expression syntax, four things are needed:
<compilation><expressionBuilders></expresionBuilders></compilation>
sectionThis post details exactly how to go about this and includes complete source control.