A resource file is an XML 1.0 document, usually UTF-8, with the root element <root> in no namespace. Its children come in this order as written by the tools, but the reader does not require the order: it reads every assembly, data, resheader and metadata element wherever it stands, and skips others.
Elements
| Element | Attributes | Content | Meaning |
|---|---|---|---|
root | none | the entries below | the document |
xsd:schema | id="root", xmlns="", xmlns:xsd, xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" | the XSD of the file: element declarations for root, metadata, assembly, data and resheader | describes the format; written by every tool; the reader ignores it. A file written by hand may leave it out |
resheader | name | <value> (older files hold the text directly) | a header value: resmimetype, version, reader or writer |
assembly | alias, name | none | gives an assembly (name, a full assembly name) a short alias that types in this file can use as their assembly part |
data | name, type, mimetype, xml:space | <value> and optional <comment> | one resource |
metadata | the same as data | the same | a value for the designer and not for the program: it is not in the compiled resources (for example, the position of a component tray) |
value | none | text | the stored form of the value |
comment | none | text | a note for the translator or developer; kept in the file, not in the resources |
The inline schema declares, for data, the attributes name (required), type, mimetype and xml:space, and the child elements value (one) and comment (zero or one), and for metadata the same with value only. For resheader it declares one value.
The headers
| Name | Written value | The reader’s rule |
|---|---|---|
resmimetype | text/microsoft-resx | must be exactly this, or the reader refuses the file |
version | 2.0 (older files: 1.3, 1.0.0.0) | read but not checked |
reader | System.Resources.ResXResourceReader, System.Windows.Forms, Version=…, Culture=neutral, PublicKeyToken=b77a5c561934e089 | the text before the first comma, trimmed, must be System.Resources.ResXResourceReader |
writer | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=… | the text before the first comma must be System.Resources.ResXResourceWriter |
The reader looks for the header names in lower case first and then compares them case-insensitively, because early files wrote ResMimeType, Version, Reader and Writer. A file whose headers do not pass (no resmimetype, or a reader or writer that is not the standard one) is not a resource file to the reader, which stops with “Invalid ResX input”. A resheader with no name is ignored. The assembly versions inside the type names differ from file to file (old files have Version=1.0.5000.0, current ones Version=4.0.0.0).
Entries
- name. The key of the resource. It is a string; the reader does not restrict it, but names that become members of the generated resource class must be valid identifiers (the code generator replaces the others). A name with a
.is conventional in Windows Forms (button1.Text, the property of a control) and in UWP (Uid.Property); names starting with>>(>>button1.Name,>>button1.Type,>>button1.Parent,>>button1.ZOrder) are the control tree entries of a localisable Windows Forms form, and$thisis the form itself. Adataentry with nonamehas the empty name. - Unique names. The reader keeps one value for a name: a second
dataentry with the same name replaces the first. The resource writer and the build reject names that match when the case is ignored. - type. A .NET type name with an assembly:
System.Drawing.Point, System.Drawing; the assembly part may be an alias declared by anassemblyelement. With notypeand nomimetypethe value is astring. - mimetype. The form of a serialised value; see types, mimetypes and values.
- xml:space.
preserveon a string entry keeps the white space of thevalue; the tools write it for every string entry. Without it, a value that is only white space is read as empty. - value. The stored form: text, typed text, or base64 with line breaks (the writers wrap base64 at 80 characters; any white space in it is ignored).
- comment. Free text.
Files made by hand and by old tools
- Files from Visual Studio .NET 2002 and 2003 write the headers with capital letters and may hold a header’s text directly inside
resheaderwith novalueelement; the reader accepts both. - Smart Device (Compact Framework) projects write type names with
System.CF.Drawingas the assembly. - ASP.NET resource files (
Name.aspx.resx,Global.asax.resx) have the same shape. - The files of the
ResourceWriterof a build (the output ofresgen) are binary and have another name; see localisation.
Not described
Known, not yet covered
- Reference: the full text of the inline XSD is not reproduced; its element and attribute declarations are summarised above.
- Reference: the meaning of the
>>and$thisentries of a Windows Forms form is described from the files found here, not from the Windows Forms designer’s source.
Unknown
- Reference: whether other names are reserved by the build’s resource generator (
ResGen,StronglyTypedResourceBuilder) was not checked.