| Previous | Next |
| E_STRING_NOT_NULL_TERMINATED | E_ASYNC_OPERATION_NOT_STARTED |
E_ILLEGAL_DELEGATE_ASSIGNMENT
Delegate assignment is not allowed in this context
E_ILLEGAL_DELEGATE_ASSIGNMENT is HRESULT 2147483672 (0x80000018) from winerror.h. AllStat describes it as “A delegate was assigned when not allowed.” In the Windows Runtime metadata, object lifetime, asynchronous operation, activation, and apartment model, the code identifies a specific failure boundary and should not be replaced by a generic COM exception.
Handling this result correctly requires the code-specific postcondition, not merely the fact that FAILED(hr) is true.
Decisive interpretation boundary
Before choosing recovery, verify that the delegate ownership model, token-based subscription rules, and current lifecycle state are known. That boundary prevents this result from being misclassified as corruption, network failure, or a reason for an unsafe automatic retry.
Also confirm that all observed objects, tokens, buffers, proxies, metadata files, or ACLs belong to the current operation generation and were not retained from an earlier attempt.
Where it is encountered
- This result can be returned during C++/WinRT, WRL,.NET projections, or native WinRT ABI calls. Record the interface, method, component version, thread, apartment, process, and correlation ID.
- This result can be returned during runtime-class activation, WinMD reflection, asynchronous objects, observable state, or view lifecycle.
- It can be returned during cross-thread and cross-apartment handoff between UI, ASTA, STA, MTA, broker, and background work.
The immediate focus for it is an event, callback slot, or runtime property whose contract rejects replacement, duplication, or assignment after a lifecycle boundary. Keep it attached to that operation; the same numeric severity outside the owning API does not supply enough context.
Correct handling and recovery
Use the documented add/remove event pattern or assign only during the permitted initialization phase. Revoke stale handlers during teardown.
Reconcile partial output and server-side effects before attempting the operation again.
Difference from nearby HRESULTs
It rejects the callback binding itself; E_ILLEGAL_METHOD_CALL can reject any method because of timing.
Tests for it should force both results and verify that object lifetime, output use, and user messaging differ.
Lifetime, retry, and cleanup rules
After it, determine whether the current object, interface pointer, call context, token, stream, metadata reader, asynchronous operation, or access-control instance remains valid. Release only resources owned by the failing attempt, cancel callbacks through their documented mechanism, and avoid double close, double commit, repeated activation, or replay of a non-idempotent remote method.
The retry policy for it should state the trigger, maximum attempts, cancellation owner, and reconciliation step for effects that may have completed elsewhere.
Practical scenario
A component attempts to overwrite a framework-owned completion delegate after startup. It changes to event-token subscription and revokes the token when the view closes.
A regression test should reproduce it, assert the raw HRESULT and all relevant outputs, then correct only the decisive condition and verify the intended success or neighboring failure result.
References
- Microsoft: C++/WinRT error handling
- Microsoft: concurrency and asynchronous operations
- Microsoft: WinMD files
- Microsoft: IAgileObject
- Microsoft: COM apartments
- Microsoft: HRESULT values
Looking for a different code? Search another status or error code.
