Export (0) Print
Expand All

ResourceReader.GetResourceData Method

Retrieves the type name and data of a named resource from an open resource file or stream.

Namespace:  System.Resources
Assembly:  mscorlib (in mscorlib.dll)

public void GetResourceData(
	string resourceName,
	out string resourceType,
	out byte[] resourceData
)

Parameters

resourceName
Type: System.String

The name of a resource.

resourceType
Type: System.String

When this method returns, contains a string that represents the type name of the retrieved resource (see the Remarks section for details). This parameter is passed uninitialized.

resourceData
Type: System.Byte[]

When this method returns, contains a byte array that is the binary representation of the retrieved type. This parameter is passed uninitialized.

ExceptionCondition
ArgumentNullException

resourceName is null.

ArgumentException

resourceName does not exist.

BadImageFormatException

resourceName has an invalid type.

FormatException

The retrieved resource data is corrupt.

InvalidOperationException

The current ResourceReader object is not initialized, probably because it is closed.

The GetResourceData method retrieves the value of a named resource as a byte array. It is typically used when the Value property throws an exception when it tries to retrieve the value of a resource.

resourceType is a string that represents the data type of the resource. It can be any of the following values:

  • The string representation of a ResourceTypeCode enumeration member that indicates the data type of the resource. ResourceTypeCode is a private enumeration that is used by Resgen.exe.to indicate that a special binary format is used to store one of 19 common data types. These include the .NET Framework primitive data types (Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Single, SByte, UInt16, UInt32, UInt64), as well as String, DateTime, and TimeSpan, In addition, the ResourceTypeCode enumeration includes the values shown in the following table.

    ResourceTypeCode value

    Description

    ResourceTypeCode.ByteArray

    The data is a byte array. This data type commonly results from the call to the ResourceWriter.AddResource(String, Byte[]) method.

    ResourceTypeCode.Null

    The data is a null reference. This data type commonly results from the call to the ResourceWriter.AddResource(String, Object) method with an object whose value is null.

    ResourceTypeCode.Stream

    The data is stored in a stream. This data type commonly results from the call to the ResourceWriter.AddResource(String, Stream) or ResourceWriter.AddResource(String, Stream, Boolean) method.

    Assuming that resourceData has not been corrupted, it can usually be converted from a byte array back to its original value by calling a BitConverter or BinaryReader method.

  • A string that contains the fully qualified name of the type whose serialized data is assigned to the resourceData argument (for example, System.String). In addition, for types that are not part of the .NET Framework class library, the string includes the name, version, culture, and public key of the assembly that contains the type. For example, the following string indicates that the serialized data represents an instance of the Person type in the Extensions namespace, which is found in version 1.0 of an assembly named Utility that has no public key and no designated culture.

    Extensions.Person, Utility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    Assuming that resourceData has not been corrupted and that the source type is available, resourceData can be converted from a byte array back to its original value by converting the byte array to a Stream object and passing the stream to the BinaryFormatter.Deserialize method.

  • The string used to describe the data type in the ResourceWriter.AddResourceData method call.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft