Cannot reference a dll in console application but I can in wpf

1.3k views Asked by At
  • I have a console application and a wpf application.
  • on both applications I have added the skype4com.dll reference

  • The code: SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();

gives an: InvalidCastExeption stating:

Unable to cast COM object of type 'System.__ComObject' to interface type 'SKYPE4COMLib.Skype'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B1878BFE-53D3-402E-8C86-190B19AF70D5}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

but when I run the same line of code in my wpf application I don't get an exception. why!?


My console application was running great until skype updated. I uninstalled skype, installed it again in order to try to solve the problem but that did not help.

2

There are 2 answers

0
Tono Nam On BEST ANSWER

After long hours of trying I decided I where going to make my wpf application a console application by adding the necessary references and classes. Then I compared and I noticed that if I added:

[System.STAThreadAttribute()]

to the main method it works!!!!!

as a result my main method now should look like:

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace ConsoleApplication3
{

    class Program
    {
        [System.STAThreadAttribute()]                
        static void Main(string[] args)
        {
            SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();
        }
    }
}

on asp.net there is not a main method. well not one that I know of. so in asp.net I had to add the AspCompat attribute equal to true.

so my asp.net aspx pages now look like:

    <%@ Page AspCompat="true" Language="C#" .... etc
1
Mharlin On

Don't use the client profile for you Console app, set it to the full .Net version.

You change it by going into the project properties -> Application -> Target Framework (Drop Down) -> Set it to .Net Framework 4 (If it's that version of .net you are running)