Missing compiler required member 'microsoft.csharp.runtimebinder.binder.convert'

C#Excel

C# Problem Overview


I first time using Excel to reading data in c# with Selenium WebDriver, but when I build this code, it pops up an error:

>"Missing compiler required member 'microsoft.csharp.runtimebinder.binder.convert'"

and the code for using excel is marked in red bellow:

 excel.Application x1Appl = new excel.Application();
 excel.Workbook x1WorkBook = x1Appl.Workbooks.Open(@"C:\app\o\SearchBy.xlsx");

 excel._Worksheet x1WorkSheet = x1WorkBook.Sheets[1];

Please let me know what is missing? Thank you!

C# Solutions


Solution 1 - C#

The reference assemblies for Office are exposed via the dynamic return type. To be able to compile you need to add a reference to Microsoft.CSharp.dll.

Solution 2 - C#

In addition to what @Alex Ghiondea says, go to the references section of your project:

Right click on references and check the prompted options.

  1. Click on add reference and a modal with the left menu (assemblies, projects, COM and browse) will appear.
  2. Click Assemblies
  3. Check Microsoft.CSharp and click Ok.
  4. Clean and build your project and the error should disappear.

enter image description here

Solution 3 - C#

If your project is targeting .Net Core or .Net Standard, then installing the Microsoft.CSharp NuGet package will solve this error.

Solution 4 - C#

Add a reference of Microsoft.CSharp to your project by using NuGet.

enter image description here

or

Install-Package Microsoft.CSharp -Version 4.7.0 for the project

Solution 5 - C#

I'm using Visual Studio 2017 Version 15.7.1 (not sure if this matters or not, but this error seems to have cropped up after I updated). I had a project that was targeting .NET Framework 3.5. So, in addition to the other answers provided for adding Microsoft.CSharp, I needed to update this project to .NET Framework 4.5, and then Microsoft.CSharp showed up under Assemblies when I went to add the reference. Before then, I had to find the absolute path to the DLL, which didn't seem to work.

For those who can't upgrade to 4.5, you can try setting EmbedInteropTypes to False for all interop references in your csproj file, as shown here: http://answers.flyppdevportal.com/MVC/Post/Thread/b1554cdd-ad9e-4453-b4d6-8eb03da175ea?category=visualstudiogeneral

Solution 6 - C#

right click on project name (in solution explorer), Add refrence : Microsoft.CSharp in the assemblies , then right click again and Clean. that's all.

Solution 7 - C#

I had this problem as well. If you right click and select Properties (While project is highlighted), there is a checkbox that says: Auto-generate binding redirects. This fixed it for me.

I am using Visual Studio 2017 and it is a C# class library.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionExcellentView Question on Stackoverflow
Solution 1 - C#Alex Ghiondea - MSFTView Answer on Stackoverflow
Solution 2 - C#eduardo92View Answer on Stackoverflow
Solution 3 - C#Kolappan NView Answer on Stackoverflow
Solution 4 - C#Karthikeyan VKView Answer on Stackoverflow
Solution 5 - C#brrrrthView Answer on Stackoverflow
Solution 6 - C#Sharif LotfiView Answer on Stackoverflow
Solution 7 - C#PatView Answer on Stackoverflow