Resource problem after converting from ASP.NET 1.1 to ASP.NET 2.0

F

Fredrik Rodin

All,

I'm having problems with my resource manager in ASP.NET 2.0 after conversion
from ASP.NET 1.1.

Here is a background:

In ASP.NET 1.1
All my user controls and aspx pages inherit from base classes. A base class
includes this property (among others...;-)):

Private m_rscResources As System.Resources.ResourceManager

Public ReadOnly Property rscResource() As System.Resources.ResourceManager
Get
If m_rscResources Is Nothing Then
m_rscResources = New
System.Resources.ResourceManager("MyPortalNamespace.Strings",
System.Reflection.Assembly.GetExecutingAssembly)
Return m_rscResources
Else
Return m_rscResources
End If
End Get
End Property

In my application root folder I have two files. One strings.resx and one
strings.sv.resx. When I call the rscResource.GetString method I simply use
the tag name to get the translation.

Label1.Text = rscResource.GetString("First name")

In 1.1 this works absolutely fine. However, In 2.0 (after conversion), it's
not working. The error message I get from .NET is:

System.Resources.MissingManifestResourceException was unhandled by user code
Message="Could not find any resources appropriate for the specified
culture or the neutral culture. Make sure
"MyPortalNamespace.Strings.resources" was correctly embedded or linked into
assembly "App_Code.lkep0udn" at compile time, or that all the satellite
assemblies required are loadable and fully signed."

I've tried to dynamically get the current executing assembly name like this:

m_rscResources = New
System.Resources.ResourceManager(System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
& ".Strings", System.Reflection.Assembly.GetExecutingAssembly)

Same error message (but 'MyPortalNamespace' is replaced).

I've tried a number of things to work around this, but I still get this
error message. I've tried placing the resource files into different
directories including App_Code, App_GlobalResources, application root etc.
None is making it better.

So, here I stand...

I want to clarify that I know how you can use resources in 2.0, but that's
from scratch. I have hundreds and hundreds of places where I use
rscResource.GetString("MyKey") and I really don't feel I want to change all
that now.

Any help and/or suggestions are more than welcome. I'll be happy to assist
with more project details in case you need it.

Thanks in advance,
Fredrik Rodin,

Stockholm, Sweden
 
E

Emil Christopher Melar

Fredrik said:
All,

I'm having problems with my resource manager in ASP.NET 2.0 after conversion
from ASP.NET 1.1.

Here is a background:

In ASP.NET 1.1
All my user controls and aspx pages inherit from base classes. A base class
includes this property (among others...;-)):

Private m_rscResources As System.Resources.ResourceManager

Public ReadOnly Property rscResource() As System.Resources.ResourceManager
Get
If m_rscResources Is Nothing Then
m_rscResources = New
System.Resources.ResourceManager("MyPortalNamespace.Strings",
System.Reflection.Assembly.GetExecutingAssembly)
Return m_rscResources
Else
Return m_rscResources
End If
End Get
End Property

In my application root folder I have two files. One strings.resx and one
strings.sv.resx. When I call the rscResource.GetString method I simply use
the tag name to get the translation.

Label1.Text = rscResource.GetString("First name")

In 1.1 this works absolutely fine. However, In 2.0 (after conversion), it's
not working. The error message I get from .NET is:

System.Resources.MissingManifestResourceException was unhandled by user code
Message="Could not find any resources appropriate for the specified
culture or the neutral culture. Make sure
"MyPortalNamespace.Strings.resources" was correctly embedded or linked into
assembly "App_Code.lkep0udn" at compile time, or that all the satellite
assemblies required are loadable and fully signed."

I've tried to dynamically get the current executing assembly name like this:

m_rscResources = New
System.Resources.ResourceManager(System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
& ".Strings", System.Reflection.Assembly.GetExecutingAssembly)

Same error message (but 'MyPortalNamespace' is replaced).

I've tried a number of things to work around this, but I still get this
error message. I've tried placing the resource files into different
directories including App_Code, App_GlobalResources, application root etc.
None is making it better.

So, here I stand...

I want to clarify that I know how you can use resources in 2.0, but that's
from scratch. I have hundreds and hundreds of places where I use
rscResource.GetString("MyKey") and I really don't feel I want to change all
that now.

Any help and/or suggestions are more than welcome. I'll be happy to assist
with more project details in case you need it.

Thanks in advance,
Fredrik Rodin,

Stockholm, Sweden

In ASP.NET 2.0 I was facing the very same problem.

I replaced my ResourceManager instance with this:
public static GetString ( string key )
{
string value =
System.Web.HttpContext.GetGlobalResourceObject("MyResx", key ) as string;

return ( value == null ) ? string.Empty : value;
}

This means:

Move your resx files to App_GlobalResources directory, and use
System.Web.HttpContext.GetGlobalResourceObject ().

Resources are now also compiled in the same manner as datasets, strongly
typed with intellisense.
ASP.NET 2.0 generates a namespace named "Resources" after you stick
files in the App_GlobalResources-directory.

So then you would refer it: Resources.MyResx.MyKey in code behind.

NOTE: Above text is if you want to use resource strings programatically
in code behind. ASP.NET 2.0 has built-in support for using resources in
controls now.

in controls you would replace the whole thing (instead of using a
resource manager instance) by using the meta: attribute as described in
MSDN: http://msdn2.microsoft.com/en-us/library/fw69ke6f
 
F

Fredrik Rodin

Thanks, Emil!

Your suggested method solved the problem:) Since I'm doing VB, here is the
code for my new class:

Public Class ResourceMapper

Public Function GetString(ByVal key As String) As String
Dim value As String =
System.Web.HttpContext.GetGlobalResourceObject("Strings", key)
Return Microsoft.VisualBasic.IIf((value Is Nothing), String.Empty, value)
End Function

End Class

/Fredrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top