mscorlib 1.0.5000.0 2.0.0.0 4.0.0.0 System.Attribute System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Interface | System.AttributeTargets.All, Inherited=false) System.Runtime.InteropServices.ComVisible(true)

You can apply this attribute to an assembly, interface, class, or structure.

By default, the common language runtime converts to ANSI characters any managed Unicode characters passed to an unmanaged method executing on Windows 98 or Windows Me. Best-fit mapping enables the interop marshaler to select a close-matching character when no exact match exists. For example, the marshaler converts the Unicode copyright character to 'c' for unmanaged methods that accept ANSI characters.

Some characters lack a best-fit representation; these characters are called unmappable. Unmappable characters are usually converted to the default '?' ANSI character. Certain Unicode characters are converted to dangerous characters, such as the backslash '\' character, which can inadvertently change a path.

provides two parameters to control aspects of best-fit mapping. You use the first parameter to toggle best-fit mapping on and off. The default value is true, which enables best-fit mapping on the assembly, interface, and class levels. An attribute applied to an interface or class overrides an assembly-level attribute. You can likewise enable or disable best-fit mapping for platform invoke calls by using the field. A value set by the platform invoke field overrides all levels of .

You can use the second parameter to control throwing an exception on unmappable characters. The default value for the field is false, which disables throwing an exception each time the runtime encounters a Unicode character that has to be converted to the '?' ANSI character. Even if best-fit mapping is true, unmappable characters generate an exception when the field is true. To tighten security, you can toggle the first parameter to false and the second parameter to true. This combination of parameter settings turns best-fit mapping off, but enables the exception-throwing mechanism as a safety precaution.

You cannot change the default values provided by when passing a managed array whose elements are ANSI Chars or LPSTRs to an unmanaged safe array. Best-fit mapping is always enabled and no exception can be thrown. Be aware that this combination can compromise your security model.

Controls whether Unicode characters are converted to the closest matching ANSI characters.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  To be added.

  Initializes a new instance of the class set to the value of the property.

  true to indicate that best-fit mapping is enabled; otherwise, false. The default is true.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean To be added.

  If best-fit mapping is false and is true, all Unicode characters that require conversion to ANSI format will generate an exception when passed to unmanaged code. Some characters are unmappable, even when best-fit mapping is true. Some characters lack a best-fit representation; these characters are called unmappable. Unmappable characters are usually converted to the default '?' ANSI character.

  Certain Unicode characters are converted to dangerous characters, such as the backslash '\' character, which can inadvertently change a path.

  Gets the best-fit mapping behavior when converting Unicode characters to ANSI characters.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  If false, the field is disabled; otherwise, an exception is thrown each time the interop marshaler encounters an unmappable character. The default false.

  Enables or disables the throwing of an exception on an unmappable Unicode character that is converted to an ANSI '?' character.