Microsoft KB Archive/839861

= A System.Resources.MissingManifestResourceException exception occurs when you try to access a localized resource =

Article ID: 839861

Article Last Modified on 5/18/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



SYMPTOMS
In a Microsoft ASP.NET application, when you try to access a localized resource, a System.Resources.MissingManifestResourceException exception may occur, and your Web browser may display an error message that is similar to the following error message:

Server Error in '/ ' Application.

Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure &quot; .strings.resources&quot; was correctly embedded or linked into assembly &quot; &quot;. baseName: .strings locationInfo: resource file name:  .strings.resources assembly: , Version= , Culture=neutral, PublicKeyToken=null

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure &quot; .strings.resources&quot; was correctly embedded or linked into assembly &quot; &quot;. baseName: .strings locationInfo: resource file name:  .strings.resources assembly: , Version= , Culture=neutral, PublicKeyToken=null

Notes
 * In the error message,  is a placeholder for the name of your ASP.NET application.
 * In the earlier error information,  is a placeholder for the version number of the primary assembly for your application.



CAUSE
This problem occurs if you use a localized resource that exists in a satellite assembly that you created by using a .resources file that has an inappropriate file name. This problem typically occurs if you manually create a satellite assembly.

To manually create a satellite assembly, you must first run the Resource File Generator (Resgen.exe), and then you must run the Assembly Linker (Al.exe). When you run Resgen.exe, if you do not specify the file name of the output file while you convert an XML-based resource format (.resx) file to a .resources file, Resgen.exe creates a .resources file that has the same file name as the input file. If the file name of your XML-based resource format file does not start with the namespace name of your application, the file name of the .resources file will not contain this namespace name either. You may run Al.exe to create a satellite assembly that contains the localized resources that exist in the .resources file. However, when you try to access a localized resource that exists in the satellite assembly, the behavior that is mentioned in the &quot;Symptoms&quot; section occurs.



WORKAROUND
To work around this problem, specify the file name of the .resources file when you run Resgen.exe. While you specify the file name of the .resources file, make sure that the file name starts with the namespace name of your application. For example, run the following command at the Microsoft Visual Studio .NET command prompt to create a .resources file that has the namespace name of your application at the beginning of the file name:

Resgen strings. .resx .strings. .resources

Notes
 * In this example,  is a placeholder for an identifier (such as &quot;ja&quot;) that you can use to specify the culture for your resources.
 * In the earlier command,  is a placeholder for the namespace name of your application.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Create an ASP.NET Web Application project that uses a localized resource. To do this, follow these steps:  Start Visual Studio .NET. Use Microsoft Visual Basic .NET or Microsoft Visual C# .NET to create an ASP.NET Web Application project that is named MyApp. By default, a Web form that is named WebForm1.aspx is created. In Solution Explorer, right-click WebForm1.aspx, and then click View Code. The code window opens.  If you are using Visual Basic .NET, add the following code at the top of the code window: Imports System.Reflection Imports System.Diagnostics Imports System.Resources Imports System.Threading Imports System.Globalization If you are using Visual C# .NET, add the following code at the top of the code window: using System.Reflection; using System.Diagnostics; using System.Resources; using System.Threading; using System.Globalization;   If you are using Visual Basic .NET, add the following code to the Page_Load event handler to try to access your localized resource: Thread.CurrentThread.CurrentUICulture = New CultureInfo(&quot;ja&quot;) Dim rm As ResourceManager = New ResourceManager(&quot;MyApp.strings&quot;, System.Reflection.Assembly.Load(&quot;MyApp&quot;)) Response.Write(&quot;Hello: &quot; + rm.GetString(&quot;myVar&quot;)) If you are using Visual C# .NET, add the following code to the Page_Load event handler to try to access your localized resource: Thread.CurrentThread.CurrentUICulture = new CultureInfo(&quot;ja&quot;); ResourceManager rm = new ResourceManager(&quot;MyApp.strings&quot;,Assembly.Load(&quot;MyApp&quot;)); Response.Write(&quot;Hello: &quot; + rm.GetString(&quot;myVar&quot;)); </li> On the Build menu, click Build MyApp.</li></ol> </li> Create an XML-based resource format file that contains a localized resource. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> On the Project menu, click Add New Item. The Add New Item - MyApp dialog box appears.</li> Under Templates, click Assembly Resource File.</li> In the Name box, replace the existing text with strings.ja.resx, and then click Open. The Data view of the strings.ja XML-based resource format file appears.</li> In the Data view, under name, type myVar .</li> In the Data view, under value, type Japanese .</li> On the File menu, click Save strings.ja.resx.</li></ol> </li> Create a satellite assembly that contains a localized resource. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> In Solution Explorer, right-click strings.ja.resx, and then click Exclude From Project.</li> In the root folder of drive C on your computer, create a folder that is named MyTemp.</li> Move the strings.ja XML-based resource format file that you saved in step 2f to the MyTemp folder.

Note The strings.ja XML-based resource format file typically exists in the MyApp folder where your other project files exist.</li> Start a Visual Studio .NET command prompt.</li> At the Visual Studio .NET command prompt, run the following command to create a .resources file:

Resgen strings.ja.resx

</li> At the Visual Studio .NET command prompt, run the following command to create the MyApp.resources.dll satellite assembly that contains your localized resources:

Al.exe /t:lib /embed:strings.ja.resources /culture:ja /out:MyApp.resources.dll

</li></ol> </li> <li>Try to access the localized resource. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>In the Bin folder of the MyApp folder where you created your project files, create a folder that is named JA.</li> <li>Move the MyApp.resources.dll satellite assembly that you created in step 3f to the JA folder.</li> <li>Switch to Visual Studio .NET.</li> <li>On the Debug menu, click Start. Your Web browser opens, and the behavior that is mentioned in the &quot;Symptoms&quot; section occurs.</li></ol> </li></ol>

<div class="references_section">