titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
197 stars 93 forks source link

ExternalException (0x80040154): CoCreateInstanceEx: Class not registered #5

Closed ericbourque29 closed 7 years ago

ericbourque29 commented 8 years ago

Hello,

I tried using your project to make a small test app but I get this Exception when trying to connect...

\ Texte de l'exception ** System.Runtime.InteropServices.ExternalException (0x80040154): CoCreateInstanceEx: Classe non enregistrée

à TitaniumAS.Opc.Client.Interop.System.Com.CreateInstance(Guid clsid, String host, NetworkCredential credential) à TitaniumAS.Opc.Client.Common.OpcServerEnumeratorAuto.CLSIDFromProgId(String progId, String host) à TitaniumAS.Opc.Client.Da.OpcDaServer.<>cDisplayClass7.b4(String host, String progId) à TitaniumAS.Opc.Client.Common.UrlParser.Parse[T](Uri opcServerUrl, Func3 withProgId, Func3 withCLSID) à TitaniumAS.Opc.Client.Da.OpcDaServer.Connect() à OPCTester.Form1.button1_Click(Object sender, EventArgs e) dans C:\Users\EB.NIKLAS\Desktop\TitaniumAS.Opc.Client-master\TitaniumAS.Opc.Client-master\OPCTester\Form1.cs:ligne 32 à System.Windows.Forms.Control.OnClick(EventArgs e) à System.Windows.Forms.Button.OnClick(EventArgs e) à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) à System.Windows.Forms.Control.WndProc(Message& m) à System.Windows.Forms.ButtonBase.WndProc(Message& m) à System.Windows.Forms.Button.WndProc(Message& m) à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

This is the simple code I used:

`using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using TitaniumAS.Opc.Client.Common; using TitaniumAS.Opc.Client.Da; using TitaniumAS.Opc.Client.Da.Browsing;

namespace OPCTester { public partial class Form1 : Form { OpcDaBrowserAuto browser;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        // Make an URL of OPC DA server using builder.
        Uri url = UrlBuilder.Build(textBox1.Text);
        var server = new OpcDaServer(url);

        // Connect to the server first.
        server.Connect();

        // Create a browser and browse all elements recursively.
        browser = new OpcDaBrowserAuto(server);
        BrowseChildren(browser);

    }

    void BrowseChildren(IOpcDaBrowser browser, string itemId = null, int indent = 0)
    {
        try
        {
            // When itemId is null, root elements will be browsed.
            OpcDaBrowseElement[] elements = browser.GetElements(itemId);

            // Output elements.
            foreach (OpcDaBrowseElement element in elements)
            {
                string text = new String(' ', indent);
                text += element;
                ListViewItem lvi = new ListViewItem();
                lvi.SubItems.Add(text);
                lvi.BackColor = Color.Red;
                listView1.Items.Insert(0, lvi);
                // Output the element.

                // Skip elements without children.
                if (!element.HasChildren)
                    continue;

                // Output children of the element.
                BrowseChildren(browser, element.ItemId, indent + 2);
            }
        }
        catch (Exception e) {

            ListViewItem lvi = new ListViewItem();
            lvi.SubItems.Add(e.ToString());
            lvi.BackColor = Color.Red;
            listView1.Items.Insert(0, lvi);                
        }
    }

}

}

Do you know what the problem might be?`

alexey-kachalov commented 8 years ago

Hello. Could you share URL you have typed in the textbox?

Biproditya commented 8 years ago

I am also getting similar kind of issue.

So, tried to make it simple. I have not done anything extra just using TitaniumAS.Opc.Client project, trying to call OpcServerEnumeratorTests to check the server connection.

Every time I receive error: Unable to cast COM object of type 'System.__ComObject' to interface type 'TitaniumAS.Opc.Client.Interop.Common.IOPCServerList2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9DD0B56C-AD9E-43EE-8305-487F3188BF7A}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

or

Unable to cast COM object of type 'System.__ComObject' to interface type 'TitaniumAS.Opc.Client.Interop.Common.IOPCServerList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{13486D50-4821-11D2-A494-3CB306C10000}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

--- Code ---- ComServer = DoComCall(comServer, "IUnknown::QueryInterface", () => comServer.QueryInterface());

trkeast commented 8 years ago

Helllo! Possibly you have not installed OPCEnum service, try install Opc Core Components (https://opcfoundation.org/developer-tools/developer-kits-classic/core-components)

duckl1ng commented 7 years ago

I had the same problem. In my case, the solution is:

alexey-kachalov commented 7 years ago

Thank you @duckl1ng ! It is useful notice. The code really should be compiled under 32-bit architecture. We'll add a notification about it.

alexey-kachalov commented 7 years ago

@duckl1ng I have created troubleshooting section in readme with you findings. ;)