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?