I’m working in VS 2010 and working on upgrading our application to .NET 4. The application is built with Excel as the base and we want to take advantage of some of the improvements to .NET for using Excel. But I ran across a strange error that seems to be caused by using an Excel Interop object in a generic dictionary. Here is the error that was generated:
C:\MyApp\TheAssembly\MyClass.cs(823,57):
error CS1769: Type 'MyApp\OtherAssemply.IMyController.SheetReports' from assembly 'c:\MyApp\OtherAssemply.\bin\Debug\OtherAssembly.dll'
cannot be used across assembly boundaries because it has a generic type
parameter that is an embedded interop type.
Here’s the actual property that has the issue:
Dictionary<Excel.Worksheet, IReportSheet> SheetReports { get;}
Are we unable to use Interop objects in generic objects? If so, this is a serious limitation in .NET 4.0. I tried setting the Embed Interop property to false, but that didn’t seem to change anything. Please let me know if there is any way around this.
A new feature of VS2010 is to embed the interop types into the assembly instead of using external interop assemblies.
The benefit is that you don’t need to distribute the interop assemblies.
The drawback is that each assembly get its own set of the interop types.
Since the type “Excel.Worksheet” is now internal to your assembly, other assemblies can’t use a generic type based on it (which is what the error message says)
You get a similar error if you do
I have not used VS2010 but I’m sure there must be an option somewhere where you can turn off the embedded interop types.