titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
193 stars 94 forks source link

CoCreateInstanceEx: Class not registered #63

Open Shrimpis opened 2 years ago

Shrimpis commented 2 years ago

Hello,

I am getting the following error when trying to connect the my opc server with a DA client: System.Runtime.InteropServices.ExternalException (0x80040154): CoCreateInstanceEx: Class not registered at TitaniumAS.Opc.Client.Interop.System.Com.CreateInstance(Guid clsid, String host, NetworkCredential credential) at TitaniumAS.Opc.Client.Interop.System.Com.CreateInstanceWithBlanket(Guid clsid, String host, NetworkCredential credential, ComProxyBlanket comProx)...

This is how my class looks like which handles the connection and browsing: `public class OPCDAClient { private OpcDaServer Server = null; private OPCClientSettings Settings; private List Listeners = new List();

    public OPCDAClient() { }

    public OPCDAClient(OPCClientSettings settings) {
        Settings = settings;
        Server = new OpcDaServer(settings.Endpoint);
        Server.Connect();
    }

    public void Browse() {
        IOpcDaBrowser browser = new OpcDaBrowserAuto(Server);

        OpcDaBrowseElement[] elements = browser.GetElements(null);

        foreach(OpcDaBrowseElement element in elements) {
            Console.WriteLine("Name: {0}, Has child: {1}", element.Name);
        }
    }
}`

Any help regarding this would be awesome!

duduyoyo commented 1 month ago

Hope this solution can help, cheers!

jklemmack commented 4 weeks ago

Hope this solution can help, cheers!

This is not a solution - you are referring to a completely separate project built with a different technology stack. It is, at best, an alternative approach.

jklemmack commented 4 weeks ago

@Shrimpis You likely don't have the right URI defined for the server. I was getting this error when I just referred to the remote IP of my OPC DA server. Updating the format to the below worked though:

The format of the URL is: “opcda://{PCName or IP Address}/{ProgID of OPCDA}”

Specifically, I used this format:

Uri url = UrlBuilder.Build("28272A37-5BF6-4F16-B300-331EE07880FD", "192.168.1.13");
using (var server = new OpcDaServer(url))
{
    server.Connect();
    ...
}

(from https://community.dataparcsolutions.com/manual/index.html#!Documents/opcdasourceconfiguration.htm)

duduyoyo commented 4 weeks ago

Hope this solution can help, cheers!

This is not a solution - you are referring to a completely separate project built with a different technology stack. It is, at best, an alternative approach.

Depends on how you define a solution. If it is as simple as using .NET to retrieve DA data back - yes, it is a similar solution. From this point it is a better and simpler solution - without heavyweight OPC SDK, no worry about DCOM, and internet accessible. As a .NET client application, user shouldn't worry about different technology stack once it can assist him to use .NET to get job done. Just my 2 cents.