By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

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

P: n/a
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("MyPortalNamespac e.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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Fredrik Rodin wrote:
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("MyPortalNamespac e.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("My Resx", 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

--
Emil Christopher Melar
Nov 19 '05 #2

P: n/a
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("St rings", key)
Return Microsoft.VisualBasic.IIf((value Is Nothing), String.Empty, value)
End Function

End Class

/Fredrik

"Emil Christopher Melar" <emil@no_spam_arpanet.no> wrote in message
news:u3**************@TK2MSFTNGP15.phx.gbl...
Fredrik Rodin wrote:
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("MyPortalNamespac e.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("My Resx",
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

--
Emil Christopher Melar


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.