"dynamic" data type is recognized as "object" when using Excel COM
See original GitHub issueI have the following simple code which defines last cell with non-empty data, defines its row and gets its value:
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp = new Excel.Application { Visible = true };
Excel.Workbook xlBook = xlApp.Workbooks[1];
Excel.Worksheet sheet = xlBook.Sheets[1] as Excel.Worksheet;
int lastRow = sheet.Cells[sheet.Rows.Count, "Q"].End[Excel.XlDirection.xlUp].Row;
dynamic value = sheet.Cells[lastRow, "Q"].Value;
When I’m building the project using .NET 5 (5.0.101 or 5.0.200-preview.20601.7 SDK), I get the following two errors in Output window:
error CS1061: ‘object’ does not contain a definition for ‘End’ and no accessible extension method ‘End’ accepting a first argument of type ‘object’ could be found (are you missing a using directive or an assembly reference?)
error CS1061: ‘object’ does not contain a definition for ‘Value’ and no accessible extension method ‘Value’ accepting a first argument of type ‘object’ could be found (are you missing a using directive or an assembly reference?)
Here are problems:
- When I’m using .NET Framework 4.8, the project is built fine without any errors and code executes perfectly. In .NET 5, however, the
dynamic
data type is somehow recognized asobject
. - I emphasized “in Output window”, because now errors do not show up in “Error List” anymore - they are now seen in “Output” window. For instance, if I remove last semicolon in my code, no errors appear in “Error List”. Instead, I should build project first, and only then error appears, but in “Output” window rather than “Error List” window.
Visual Studio Version: 16.9.0 Preview 2.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (7 by maintainers)
Top GitHub Comments
@terrajobst helpfully figured out what I was missing and created a repro. The part I was missing is that it needs to be a WPF project. In that case the reference is not passed as
EmbedInteropTypes
.Moving to the WPF repo for triage.
Thank you @JohnyL and @jaredpar for the report and investigation. Capitalizing the ‘T’ worked for me locally.