I have a class in my project that accesses Excel worksheets. After upgrading from .Net 4.8 to .Net 8.0, every line using the "value2' or 'value' is an error. The class wont even compile. I made sure to add Microsoft.Office.Interop..Excel to the dependencies. The error is;
CS1061 'object' does not contain a definition for 'Value2' and no accessible extension method 'Value2' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Does anyone know what I can do to fix this?
Thanks,
Anupam MaitiPosted Sep 26, 2024, 6:56 PM
In .NET 6 and later, accessing COM properties might require casting to the appropriate types. You may need to cast
ExcelWorksheet.Cells[row, col]to a range before accessingValue2.Can you try this below ?
Make sure project is configured to support COM interop. This includes setting the correct target framework in your
.csprojfile:For more refer this: https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/interop/how-to-access-office-interop-objects