471,887 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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

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
2 5415
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
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.

Similar topics

2 posts views Thread by Arjen | last post: by
9 posts views Thread by Tom the Canuck | last post: by
3 posts views Thread by Allen | last post: by
9 posts views Thread by Alf P. Steinbach | last post: by
5 posts views Thread by Daniel | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.