System.Runtime.InteropServices.DllImportAttribute.ThrowOnUnmappableChar Field

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

Syntax

public bool ThrowOnUnmappableChar

Remarks

true to indicate that an exception is thrown each time the interop marshaler converts an unmappable character; false to indicate that the DllImportAttribute.ThrowOnUnmappableChar field is disabled. This field is false 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 provide 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.

Note:

Certain Unicode characters are converted to dangerous characters, such as the backslash '\' character, which can inadvertently change a path. By setting the DllImportAttribute.ThrowOnUnmappableChar field to true, you can signal the presence of an unmappable character to the caller by throwing an exception.

Note:

You cannot change the default values provided by the DllImportAttribute.BestFitMapping and DllImportAttribute.ThrowOnUnmappableChar fields 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 is thrown. Be aware that this combination can compromise your security model.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0