Skip to content

"dynamic" data type is recognized as "object" when using Excel COM #4203

@JohnyL

Description

@JohnyL

I 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:

  1. 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 as object.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions