Question

Since upgrading a project from VS2010 to VS2012 I'm getting the error:

'System.__ComObject' does not contain a definition for .WithComCleanup())

When running this command line of code:

using (var cell = usedRange.Resource.Find(reservedWord, LookIn: XlFindLookIn.xlFormulas, After: usedRange.Resource.Cells[usedRange.Resource.Rows.Count, usedRange.Resource.Columns.Count]).WithComCleanup())
Était-ce utile?

La solution

Thought I'd share the solution to this annoying problem, when executing the line in the intermediate window you get the tip:

Embedded interop type 'Microsoft.Office.Interop.Excel.XlFindLookIn' is defined in both 'Excel.dll' and 'XYZ.ExcelAddin.ABC.dll'. Some operations on objects of this type are not supported while debugging. Consider casting this object to type 'dynamic' when debugging or building with the 'Embed Interop Types' property set to false.

I solved the problem by turning Embed Interop Types to False for the reference DLL Microsoft.Office.Interop.Excel

Autres conseils

I solved the problem by turning Embed Interop Types to False for the reference DLL Microsoft.Office.Interop.Excel, but I get message:

System.IO.FileNotFoundException: "Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. Не удается найти указанный файл."
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top