Avatar ·

Error "Interop type cannot be embedded" in C# when working with COM

Hello! I'm a beginner in C# and trying to connect to Excel via COM objects. I have Visual Studio 2010, .NET Framework 4.0 project. I added a reference to the Microsoft.Office.Interop.Excel library through the COM tab in References. Wrote a simple code: ```csharp using Excel = Microsoft.Office.Interop.Excel; class Program { static void Main() { var excelApp = new Excel.Application(); excelApp.Visible = true; excelApp.Quit(); } } ``` When compiling I get the error: "Interop type 'Microsoft.Office.Interop.Excel.ApplicationClass' cannot be embedded. Use the applicable interface instead." I googled it but didn't understand anything. Why does this error occur? What does "cannot be embedded" mean? And how to fix it? I just need to open Excel and write data to a