The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,953 other followers

Archive for March 20th, 2012

.NET/C#: Resolved errors “The type ‘NameSpace.TypeNameClass’ has no constructors defined” and “Interop type ‘NameSpace.TypeNameClass’ cannot be embedded. Use the applicable interface instead.” (via Stack Overflow: Interop type cannot be embedded)

Posted by jpluimers on 2012/03/20

When moving the Microsoft Scripting Runtime interop code from .NET 1.x to 4.x, I got these errors:

Error1: The type 'Scripting.FileSystemObjectClass' has no constructors defined
Error21: Interop type 'Scripting.FileSystemObjectClass' cannot be embedded. Use the applicable interface instead.

Though the first answers on the question seem to adequately resolve the problem, they merely cure the symptom: turning off the embedding of the PIA (Primary Interop Assembly).

The below answer by Michael Gustus (which only has a few votes, so please vote it up) actually explains what is going on, and solves the cause:

In most cases this error is the result of code which tries to instantiate a COM object e.g. here piece of code starting up Excel:

Excel.ApplicationClass xlapp = new Excel.ApplicationClass();

Typically, in .Net 4 you just need to remove the ‘Class’ suffix and compile the code:

Excel.Application xlapp = new Excel.Application();

MSDN explanation here.

Hence I like the comment by Tyrsius on this answer as well:

This was more useful than the marked answer, as I needed the functionality of the embedded Interop. This solved both problems, thank you!

The above answer tells you to not use the class type, but the interface type, just like the error states. And the answer implicitly tells you the class type is ApplicatoinClass, and the interface is Application.

These are the declarations for the PIA interface: Read the rest of this entry »

Posted in .NET, C#, C# 4.0, Development, Software Development | Leave a Comment »

%d bloggers like this: