1

Possible Duplicate:
Single-threaded apartment - cannot instantiate ActiveX control

I am developing a Asp.net template web based application in Visual Studio 2010. Aim of the application is to read the data from ID Tech card swipper.

#Default.aspx:
# It contain a Button
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</h2> </asp:Content>

Whereas following is .cs file:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AxOposMSR_CCO;

namespace WebApplication1
{   
public partial class _Default : System.Web.UI.Page
{
    AxOPOSMSR axOPOSMSR = new AxOPOSMSR();
    protected void Page_Load(object sender, EventArgs e)
    {

    }


   protected void Button1_Click(object sender, EventArgs e)
     {
        if (axOPOSMSR.Open("IDTECH_SECUREMAG_USBKB") == 0)
        {
            axOPOSMSR.ClaimDevice(100);
            axOPOSMSR.DeviceEnabled = true;
            axOPOSMSR.DataEventEnabled = true;
            Console.WriteLine("cons called");

        }

    }
}

}

When i tried to run this project it shows:

ActiveX control 'ccb90122-b81e-11d2-ab74-0040054c3719' cannot be 
instantiated because the current thread is not in a single-threaded apartment.

I googled it and it shows that i have to create an object of Active X control and use that object in my web application. I also followed some blogs and tutorial but didn't got any better explanation.

I am newbie in C#. What should i do to solve this issue?

Please explain me in the context of above application.

Community
  • 1
  • 1
Amit Pal
  • 10,604
  • 26
  • 80
  • 160

0 Answers0