ArgumentException when assigning COM object to DependencyProperty in Workflow Foundation - type mismatch issue

I’m working on a Workflow Foundation activity that includes a dependency property to hold a COM interface object. Here’s my configuration:

public IDocument Document { get; private set; }
// Note: IDocument is a COM interface

public static DependencyProperty DocumentProperty = DependencyProperty.Register(
    "Document",
    typeof(IDocument),
    typeof(MyCustomActivity));

When I attempt to set the value of this dependency property in my activity code:

this.Document = GetDocumentFromSomewhere();
SetValue(DocumentProperty, this.Document);

The call to SetValue throws an ArgumentException, indicating there’s a type mismatch. The error message explains that the dependency property expects the IDocument type, but instead, it receives a System.__ComObject.

If I modify the registration of the dependency property to use typeof(object) rather than typeof(IDocument), it works perfectly. However, this change eliminates the type safety that I want to maintain.

Has anyone faced this issue relating to COM interop with WF dependency properties? Is there a solution to keep type safety when dealing with COM objects?

totally get ya, had the same prob. .NET can be a bit funky with COM stuff. i made a wrapper class for the COM interface, like a bridge, and it worked! might save you a lot of headache.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.