Cannot use dll in projects other than wpf applicaion

443 views Asked by At

This is really strange. If I run this in a wpf application:

SKYPE4COMLib.Skype mySkype = new SKYPE4COMLib.Skype();

I get no errors.

I want to run that in a asp.net application. when I do run it there I get: enter image description here

note that I don't get any build errors and the error arises at run-time. The SKYPE4COMLib.Skype class is provided by Skype and can be downloaded from here. I don't understand why I am able to instantiate an object from that class just if I am using a wpf appliation.

Things I have tried: (recall I want to use that library from my asp.net application)

1) Adding a wpf application to my solution. Then referencing that project from my asp application. I get the same error.

2) Tried to create a web service and instantiate the class in the web service. That does not work eather.

3) Change the target framework from .Net Framewrok 4 Client Profile to different ones. This solved the problem I was able to instantiate the class but then I am not able to call the methods.

I am having a hard time understanding why I am able to instantiate an object from a class if I am in a wpf application but not in a .net application or even a console application! I seems as if skype is trying to block that on purpose.

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
Asaf On

Maybe the user account in which your web service runs (aspnet) does not have sufficient privilege to do that? Take a look here and see if impersonation works for you.