What does HRESULT 0x80020008 (DISP_E_BADVARTYPE) mean?

 
Previous Next
DISP_E_NONAMEDARGS DISP_E_EXCEPTION

DISP_E_BADVARTYPE

Automation call contains an invalid VARIANT type

DISP_E_BADVARTYPE is HRESULT 2147614728 (0x80020008) from winerror.h. AllStat describes it as “Bad variable type.” The value must be interpreted at VARIANTARG validation before or during IDispatch invocation, because the same high-level symptom can come from a different contract boundary and require different cleanup.

The decisive Interpretation is that a VARIANT has an unsupported, reserved, inconsistent, or malformed VARTYPE encoding. The operational record for it needs the native value, symbolic constant, component build, and call phase; the message alone is insufficient.

Where the result appears

  • This result is returned while Automation binds or executes VARIANTARG validation before or during IDispatch invocation.
  • retain the member name and DISPID, invocation flags, LCID, cArgs, cNamedArgs, and the exact VARIANTARG sequence in reverse Automation order.
  • The output contract for it includes puArgErr, EXCEPINFO, result VARIANT, by-reference values, and SAFEARRAY lock or ownership state; inspect them before cleanup.

Separate caller state from runtime and server state first; otherwise cleanup and retry may target the wrong generation of the operation.

Typical causes and interpretation boundary

Common cause categories for it are: the VARIANT was not initialized; flags are combined illegally; the union field does not match vt; memory corruption changed the tag. Each possible cause of this result predicts different outputs and recovery behavior, which should be verified explicitly.

The check that separates this result from nearby HRESULTs is: a VARIANT has an unsupported, reserved, inconsistent, or malformed VARTYPE encoding. Without proof of the distinguishing condition for it, the safest action is to preserve evidence and refrain from destructive cleanup.

Evidence and telemetry

  • Record this result with the object CLSID or ProgID, interface identity, member DISPID, dispatch flags, and type-library version.
  • capture vt value; union field used; VT_BYREF and VT_ARRAY flags; initialization path; ownership and VariantClear result.
  • Log VARIANT type tags, dimensions, bounds, lengths, and null/empty distinctions for it, but redact actual confidential argument values.
  • Preserve the caller language/runtime, generated interop version, LCID, and whether the call crossed a process boundary when it occurs.
  • After it, call VariantClear, SysFreeString, SafeArrayDestroy, or release interfaces only for values whose ownership was transferred by the documented contract.

A useful it event contains ownership and shape information, not raw documents, passwords, access tokens, or full Automation values.

Correct handling and recovery

The appropriate recovery is to initialize with VariantInit, assign a supported VARTYPE and matching field, validate custom marshaling, and clear only owned values. Repeat the operation only after the failed condition has changed and the caller can distinguish a duplicate effect.

When it is returned, use the documented output contract and reconcile remote or persistent effects before replaying the request.

Practical scenario

A native caller leaves stack garbage in vt before assigning a BSTR pointer; VariantInit removes the invalid type tag.

An automated test for it should verify raw HRESULT, output ownership, cleanup behavior, and the absence of an unsafe automatic retry.

Difference from related HRESULTs

DISP_E_TYPEMISMATCH means a valid VARIANT cannot satisfy the parameter type; it means the VARIANT representation itself is invalid.

The comparison matters operationally for it: one result may permit fallback while the other requires repair, cancellation, or state reconciliation.

Developer and administrator guidance

Automation adapters should handle it at the dispatch boundary and expose the member, parameter, and type information needed to repair the call. A generic retry after <code>it</code> with unchanged DISPPARAMS usually repeats the same deterministic binding error.

Deployment owners should compare the registered type library and server binary as one versioned unit. After <code>it</code>, re-registering arbitrary DLLs or changing locale system-wide is inappropriate unless the captured metadata proves registration or LCID drift.

References


Looking for a different code? Search another status or error code.