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

Error : Invalid Resx file

Expert 100+
P: 487
Expand|Select|Wrap|Line Numbers
  1. Assembly assembly = Assembly.GetExecutingAssembly();
  2. ResourceManager rm = new ResourceManager("NameSpace.Demo", assembly, null);
  3.             try
  4.             {
  5.                 logo.Image = (Image)rm.GetObject("WroxLogo");
  6.                 textTitle.Text = rm.GetString("Title");
  7.             }
  8.             catch (Exception ex)
  9.             {
  10.                 MessageBox.Show(ex.Message.ToString());
  11.             }
Hi, I created a Demo.resx and I included it to my project, when I try to compile it showing.
Error :Invalid Resx file. Invalid character in the given encoding. Line 1, position 1. <File Path>\Demo.resx
Can any one explain why this error is occurring and how to rectify it?

Front-end : C# 2005
Nov 7 '07 #1
Share this Question
Share on Google+
5 Replies


Plater
Expert 5K+
P: 7,872
Umm, resx files look NOTHING like that.
Are you sure you don't want a new class file?

This is an example of a resx file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <root>
  3. <!-- 
  4.     Microsoft ResX Schema 
  5.  
  6.     Version 2.0
  7.  
  8.     The primary goals of this format is to allow a simple XML format 
  9.     that is mostly human readable. The generation and parsing of the 
  10.     various data types are done through the TypeConverter classes 
  11.     associated with the data types.
  12. -->
  13.   <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  14.     <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
  15.     <xsd:element name="root" msdata:IsDataSet="true">
  16.       <xsd:complexType>
  17.         <xsd:choice maxOccurs="unbounded">
  18.           <xsd:element name="metadata">
  19.             <xsd:complexType>
  20.               <xsd:sequence>
  21.                 <xsd:element name="value" type="xsd:string" minOccurs="0" />
  22.               </xsd:sequence>
  23.               <xsd:attribute name="name" use="required" type="xsd:string" />
  24.               <xsd:attribute name="type" type="xsd:string" />
  25.               <xsd:attribute name="mimetype" type="xsd:string" />
  26.               <xsd:attribute ref="xml:space" />
  27.             </xsd:complexType>
  28.           </xsd:element>
  29.           <xsd:element name="assembly">
  30.             <xsd:complexType>
  31.               <xsd:attribute name="alias" type="xsd:string" />
  32.               <xsd:attribute name="name" type="xsd:string" />
  33.             </xsd:complexType>
  34.           </xsd:element>
  35.           <xsd:element name="data">
  36.             <xsd:complexType>
  37.               <xsd:sequence>
  38.                 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
  39.                 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
  40.               </xsd:sequence>
  41.               <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
  42.               <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
  43.               <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
  44.               <xsd:attribute ref="xml:space" />
  45.             </xsd:complexType>
  46.           </xsd:element>
  47.           <xsd:element name="resheader">
  48.             <xsd:complexType>
  49.               <xsd:sequence>
  50.                 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
  51.               </xsd:sequence>
  52.               <xsd:attribute name="name" type="xsd:string" use="required" />
  53.             </xsd:complexType>
  54.           </xsd:element>
  55.         </xsd:choice>
  56.       </xsd:complexType>
  57.     </xsd:element>
  58.   </xsd:schema>
  59.   <resheader name="resmimetype">
  60.     <value>text/microsoft-resx</value>
  61.   </resheader>
  62.   <resheader name="version">
  63.     <value>2.0</value>
  64.   </resheader>
  65.   <resheader name="reader">
  66.     <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  67.   </resheader>
  68.   <resheader name="writer">
  69.     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  70.   </resheader>
  71. </root>
  72.  
Nov 7 '07 #2

Expert 100+
P: 487
Thank you plater.
Expand|Select|Wrap|Line Numbers
  1.           ResourceWriter rw = new ResourceWriter("Demo.resx");
  2.           using (Image image = Image.FromFile("logo.gif"))
  3.           {
  4.              rw.AddResource("WroxLogo", image);
  5.              rw.AddResource("Title", "Professional C#");
  6.           }
Actually, I am encoding a .gif file and created a resx file through code then referred(Added) to my project.
I am unable to understand the concept of ‘Resource writer’, ‘Resource Reader’, and ‘Resource Manager’. Can any one give some simple example to understand the concept (and if you have time please give with explanation)?
Thank you.
Nov 12 '07 #3

Expert 100+
P: 487
I am getting this Exception..

"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"Demo.resources\" was correctly embedded or linked into assembly \"NameSpace\" at compile time, or that all the satellite assemblies required are loadable and fully signed."

Till i am trying...

Changed the Code like

ResourceManager rm = new ResourceManager("Demo", Assembly.LoadFile(@"filePath/Demo.resources"));

Now, Here i am getting error
Attached Images
File Type: jpg Error_80131018.JPG (17.8 KB, 464 views)
Nov 12 '07 #4

Expert 100+
P: 487
My AssemblyVersion is
Expand|Select|Wrap|Line Numbers
  1. [assembly: AssemblyVersion("1.0.0.0")]
  2. [assembly: AssemblyFileVersion("1.0.0.0")]
I am Creating Resource file
Expand|Select|Wrap|Line Numbers
  1.       ResourceWriter rw = new ResourceWriter("Demo.resources");  
  2.           using (Image image = Image.FromFile("logo.gif"))
  3.           {
  4.              rw.AddResource("WroxLogo", image);
  5.              rw.AddResource("Title", "Professional C#");
  6.              rw.Close();
  7.          }
I added the resource file to my project and in below code i am get back my image and title
Expand|Select|Wrap|Line Numbers
  1. ResourceManager rm = new ResourceManager("Demo", Assembly.GetExecutingAssembly());
  2.             try
  3.             {
  4.                 logo.Image = (Image)rm.GetObject("WroxLogo");
  5.                 textTitle.Text = rm.GetString("Title");
  6.             }
  7.            //Catch Block here
  8.  
Expand|Select|Wrap|Line Numbers
  1. logo.Image = (Image)rm.GetObject("WroxLogo");
in this line My problem Starts and showing error

"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"Demo.resources\" was correctly embedded or linked into assembly \"Namespace\" at compile time, or that all the satellite assemblies required are loadable and fully signed."


Can any one explain me why this Exception is throwing?
Nov 12 '07 #5

Expert 100+
P: 487
I solved my problem.

I am using ResourceManager, which is wrong
I have to use ResourceSet
ResourceSet rs = new ResourceSet("Demo.resources");
Nov 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.