Interop type 'OneNote.Application' cannot be embedded. - by J Buckman

Status : 

  External<br /><br />
		This item may be valid but belongs to an external system out of the direct control of this product team.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 508465 Comments
Status Closed Workarounds
Type Bug Repros 6
Opened 11/5/2009 5:09:12 AM
Access Restriction Public


I'm trying to access a OneNote file using Microsoft.Office.Interop.OneNote, but I get "Interop type 'Microsoft.Office.Interop.OneNote.Application' cannot be embedded.  Use the applicable interface instead."

The same code works fine in VS 2008
Sign in to post a comment.
Posted by John Young on 12/8/2009 at 4:38 AM
Thank you for that explanation. Everything works absolutely fine here now, :)
Posted by Misha Shneerson - MSFT on 12/7/2009 at 11:21 AM
One of the limitations for 'Embed Interop Types' feature has been that classes cannot be used when embedding an assembly. This limitation has to do with servicing - it is safe to embed metadata but not anything that can potentially contain executable code. Luckily, in most cases you do not need to use classes from interop assemblies and minor code tweaking is needed to successfully compile with EIT=true

Let's address the most common case of this error first (which do not apply to OneNote case - OneNote "interop assembly" is a broken "interop assembly" and type embedding functionality should not apply to it - als see the workaround section)
I will also address the constants from EnvDTE.Constants /VSLangProj below

In most cases (such as error for the usage of UPnPNATClass as noted in one of the comments) this error can be addressed by renaming all occurences of class type usage to the corresponding interface. To find what the corresponding interface is - just look at the definition of the class and examine the set of interfaces the class derives from. Find the interface that has CoClass attribute - this is the interface you should be using. In most cases this interface will have the same name as the class but w/o the Class suffix.

So, for example:
1. Your application is doing Excel automation. Replace all occurences of Excel.ApplicationClass with Excel.Application
2. Your application is dealing with NATUPN - replace all occurences of UPnPNATClass with UPnPNAT
Then compile and run the code.

Now, for the EnvDTE stuff, there should be a recommendation coming from the VSIP team encouraging to use Type Embedding. Unfortunately, some constants in the EnvDTE assembly cannot be embedded. For these you will need manually embed the values of the constant into your project - - since those are constant fields in the abstract classes and will never change - this is a safe thing to do.

In the IDE you can right click on the value you need to embed, then copy&paste the values locally.
For example, if my C# code uses EnvDTE.Constants.vsDocumentKindText I will receiving the following error:
'EnvDTE.Constants' does not contain a definition for 'vsDocumentKindText'
Interop type 'EnvDTE.Constants' cannot be embedded. Use the applicable interface instead.

In the IDE I will right click on vsDocumentKindText and chooce "Go To Defnition". This will take me what appears to be the definition of the constants class. I will copy the following lines and paste it in my code:
    public abstract class Constants
        public const string vsDocumentKindText = "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}";

Then I will make the Constants class 'internal' and slightly rename it, change EnvDTE.Constants to EnvDTEConstants and compile:
    internal abstract class EnvDTEConstants
        public const string vsDocumentKindText = "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}";

Posted by wvdpost on 11/19/2009 at 4:14 AM
I've got the same error when using 'VSLangProj.PrjKind'.
VS2010 Ultimate V.10.0.21006.1 B2Rel
Posted by John Young on 11/17/2009 at 2:08 PM
I also get 'Interop type 'NATUPNPLib.UPnPNATClass' cannot be embedded. Use the applicable interface instead.'

with this code...

private static NATUPNPLib.UPnPNATClass _UPnPNat = null;

A reference to the NATUPNPLib type library has been added.

Visual Studio 2010 Beta 2 on Windows 7.
Posted by srikalyan on 11/14/2009 at 1:09 PM
I am sorry but I got this bug in vs 2010 beta 2
Posted by srikalyan on 11/14/2009 at 1:04 PM
Even I have got the same error message while developing an addin.
The message was
"Interop type 'EnvDTE.Constants' cannot be embedded. Use the applicable interface instead."
I would like to know if there is any get around with this bug.

Posted by JackStrada on 11/14/2009 at 5:45 AM
I got a similar message using EnvDTE constants.

The compiler error message is:

"Error 1 Interop type 'EnvDTE.Constants' cannot be embedded. Use the applicable interface instead."

Posted by Microsoft on 11/11/2009 at 12:58 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you
Posted by Microsoft on 11/9/2009 at 12:53 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted.