简体   繁体   中英

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

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!

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 .

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.

在此处输入图片说明

如果您的项目面向 .Net Core 或 .Net Standard,则安装Microsoft.CSharp NuGet 包将解决此错误。

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

在此处输入图片说明

or

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM