Cry about...
MS-Windows Troubleshooting
error CS1752: Interop type 'Some.Type' cannot be
embedded
Symptom:
When compiling the following error is generated:
error CS1752: Interop type 'Some.Type' cannot be embedded.
Use the applicable interface instead.
where Some.Type[] is the COM type you are trying
to use.
This may also be accompanied with the error:
error CS0143: The type 'Some.Type' has no constructors
defined
Annoyingly in the Visual Studio "Error List" only the second of these
errors ("The type ... has no constructors defined.") may be shown, and
to see the real errors you will need to view the "Output".
Cause:
One of the enhancements introduced with .NET 4 is that the common
language runtime now supports embedding of type information for COM
types directly into managed assemblies, instead of requiring the
assembly to obtain type information from the interop assemblies.
If you want to read more about this then see the Microsoft msdn
article "Type
Equivalence and Embedded Interop Types"
This is why the error goes away if compiling for a .NET framework
prior to .NET 4 - because the default behaviour has changed with .NET 4.
In the case of this error, the interop type information cannot be
embedded. Hence the error. (I assume this is function of the COM
assembly, but that is only a guess on my part.)
Possible Remedies:
- Change the .NET framework to a framework prior to .NET 4.
This probably is not an ideal solution.
- Tell Visual Studio not to embed the interop types for that
assembly.
To do this in Visual Studio 2010:
- Identify the namespace: In the code where you have the
error, right click on the type and select "Go To Definition".
From this you should be able to identify the name of the
namespace which contains the type - this is the name of the
reference you will use below.
- In the Solution Explorer, expand the list of References for
the project.
If you are using VB rather than C# then you will need to look
in the project settings for the list of references.
- Right click the the reference that you identified above in
step 1, and select "Properties".
- In the reference's properties change the property "Embed
Interop Types" from "True" to "False".
The error should then disappear.
These notes have been tested within Microsoft Visual Studio
.NET 2010 (.NET 4), and may apply to other
versions as well.
About the author: Brian Cryer
is a dedicated software developer and webmaster. For his day job he
develops websites and desktop applications as well as providing
IT services. He moonlights as a technical author and consultant.
|