14

I am facing this error on changing a Sub to a Function in VB.Net

Type System.Collection.Generic.List(Of mshtml.IHTMLDocument2) cannot be used across assembly boundaries because it has a generic type parameters that is an embedded interop type.

Does anyone knows how to get it resolved?

prem
  • 3,348
  • 1
  • 25
  • 57

2 Answers2

17

I fixed this by making sure that all assemblies had "Embed Interop Types" to FALSE.

It seems that usually when you use a COM library that parameter is set to true by default.

JasonS
  • 7,443
  • 5
  • 41
  • 61
  • 6
    I would upvote this if you explained what "Embed Interop Types" actually means/does. Not that I couldn't look it up myself, but I don't think assembly-property changes with the potential for far-reaching implications should be recommended frivolously. – Ross Brasseaux Feb 20 '17 at 16:19
  • @Lopsided it's not recommended frivolously. it's recommended to people who are getting the OP's error. I don't think this recommendation could get any more directed than that. – JasonS Feb 20 '17 at 18:46
  • 1
    When I attempted this solution it broke my library as I get the following error: Non-invocable member 'IHTMLElement.children' cannot be used like a method. So this may fix the OP's issue but to @Lopsided 's point it does have side effects. – jonyfries Jan 08 '20 at 19:56
  • JasonS making this change has side-effects beyond just fixing the OP's error. There are other considerations. Otherwise we could just set EmbedInteropTypes to False in all circumstances. Sometimes it needs to be True. I think that's what @Ross is getting at. – Hugh W Oct 31 '22 at 10:29
16

Changing the return type from List(Of mshtml.IHTMLDocument2) to IList(Of mshtml.IHTMLDocument2) or IEnumerable(Of mshtml.IHTMLDocument2) resolves the issue.

prem
  • 3,348
  • 1
  • 25
  • 57