2

I added to the top of the form

using mshtml;

IHTMLDocument2 doc = (IHTMLDocument2)webbrowser1.Document.DomDocument;
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

The error is on:

(IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

Error 3 One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?

  • 2
    Are any of the types underlined in the IDE? If you google the type names, you should get a link to MSDN that will tell you what assembly the object is in. – Tim Jan 25 '16 at 18:41
  • The solution was to add Microsoft.CSharp as reference once added this dll it's all working. Not sure why i needed it. I missed this error i had too 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported and once added the csharp dll it's all fine now. – Falcons Myman Jan 25 '16 at 19:27

2 Answers2

2

Do remember that just by adding the statement Using mshtml; (considering that all the types used falls under mshtml dll) will not bring in the referenced dll. You will also need to add the reference of the dll to your project Reference folder.

Make sure you have done that.

Rahul
  • 76,197
  • 13
  • 71
  • 125
  • I did i added it from this directory C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll maybe it's the wrong dll? After added it i did the using mshtml; but still getting this error. – Falcons Myman Jan 25 '16 at 18:57
  • Yes, right click on your project Reference folder -> add reference -> from .NET tab add the dll you want. – Rahul Jan 25 '16 at 18:59
  • @FalconsMyman, is it a COM dll? how did you obtained that dll? – Rahul Jan 25 '16 at 19:05
  • @Rahul mshtml is part of .net framework. i just tried adding it. it works fine and the code compiles as well. wonder why it's not working for the op. – Fᴀʀʜᴀɴ Aɴᴀᴍ Jan 25 '16 at 19:07
  • Rahul from this directory C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll i saw it in another stackoverflow answer for using the IHTMLDocument2 since first time IHTMLDocument2 wasn't exist then after adding this dll now it's finding and using the IHTMLDocument2 but giving me this error. – Falcons Myman Jan 25 '16 at 19:07
  • @FᴀʀʜᴀɴAɴᴀᴍ, NO that's wrong. It's not part of core .NET framework rather it's a office interop assembly (COM assembly). Check MSDN. – Rahul Jan 25 '16 at 19:10
  • 1
    @FalconsMyman, check this post once http://stackoverflow.com/questions/2068159/could-not-load-file-or-assembly-microsoft-mshtml-strong-name-validation-fai – Rahul Jan 25 '16 at 19:10
  • @Rahul Oh, yes sorry. I meant that it's not an external library. Although MS Office assemblies are external... whatever.. my bad. – Fᴀʀʜᴀɴ Aɴᴀᴍ Jan 25 '16 at 19:11
1

You need to add a reference to the Microsoft.mshtml assembly. Follow these steps to do so:

  • Project → Add Reference
  • Go to the Extensions tab (under Assemblies) on the left
  • Make sure the checkbox next to Microsoft.mshtml is checked.
  • Press OK.

Now everything should work fine.

You may see more than one entry for Microsoft.mshtml in the listed assemblies. In that case select any one of them (preferably the newest version).

Fᴀʀʜᴀɴ Aɴᴀᴍ
  • 6,131
  • 5
  • 31
  • 52
  • Tried now again same error. Before i added the dll file from C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll and got the error now i tried as you said i saw one Microsoft.mshtml.dll added it and still same error. – Falcons Myman Jan 25 '16 at 19:02
  • did you try my steps above? don't add the dll directly. use the reference adder (..kind of) dialog box as in the answer. – Fᴀʀʜᴀɴ Aɴᴀᴍ Jan 25 '16 at 19:06
  • Farhan i tried your way too. I saw there one Microsoft.mshtml added it but still same error. – Falcons Myman Jan 25 '16 at 19:09
  • @FalconsMyman I would guess you forgot the checkbox. make sure it's checked. only highlighting and pressing ok won't do – Fᴀʀʜᴀɴ Aɴᴀᴍ Jan 25 '16 at 19:10