Why the conversions between compatible reference types will compile (Excel 2010, .Net 4.5) in this case
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application excelApplication = null;
excelApplication = new Excel.Application();
Excel.Worksheet worksheet = workbook.Worksheets[1] as Excel.Worksheet;
and in the case below it will not, although I saw exampales shown like that:
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1];
In this case I get the following compiling error :
> CSC : error CS0518: Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not
defined or imported
> error CS1969: One or more types required to compile a dynamic expression cannot be
found. Are you missing a reference?
Best,
EDIT : Thanks to the both answerer below the following explanation sounds reasonable:
without including Microsoft.CSharp in the Project References for projects with .Net Version >= 4.0, support for inter operation between the Dynamic Language Runtime (DLR) and C# is not possible, i.e. no dynamic cast is possible.