Issue Registering OPC NET API DLLs: CoCreateInstanceEx Error Message|Classic OPC: DA, A&E, HDA, XML-DA, etc.|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Issue Registering OPC NET API DLLs: CoCreateInstanceEx Error Message
Avatar
Michael Koller
Member
Members
Forum Posts: 3
Member Since:
01/29/2024
sp_UserOfflineSmall Offline
1
01/30/2024 - 00:21
sp_Permalink sp_Print

Hello,

I have downloaded the OPC NET API assemblies (https://opcfoundation.org/deve.....urce-code/) and built them using Visual Studio. I had to change the target framework to 4.8, as the original targeted one is not installed on my PC, but I did not make any other changes to the Visual Studio project.

The problem arises after I paste them into the GAC and use the command "regasm.exe" (from C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe) for the DLLs (OpcNetApi.Com.dll, OpcNetApi.dll, OpcNetApi.Xml.dll, and OpcComRcw.dll). When I try to run the following code:

using Opc.Da;

public class OpcServerList
{
    public void ListServers()
    {
        ServerEnumerator enumerator = new ServerEnumerator();
        Opc.Server[] servers = enumerator.GetAvailableServers(Specification.COM_DA_20);
    }
}

I encounter the following exception:

System.Runtime.InteropServices.ExternalException: CoCreateInstanceEx: Class not registered

It's worth noting that when using a third-party installer for the OPC NET API assemblies, everything runs smoothly. This leads me to suspect that I am missing a step when registering the DLLs. Could you please help me? I've been stuck on this issue for several days now.

P.S.: The code is actually executed in LabVIEW, so the C# code shown above is a direct transcription of the LabVIEW code I am using.

Thank you very much
Michael

Avatar
Randy Armstrong
Admin
Forum Posts: 1568
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
01/30/2024 - 01:59
sp_Permalink sp_Print

You should not need to call regasm to use the assemblies since you do not call these assemblies from non .NET code and OpcComRcw.dll should be statically linked.

Avatar
Michael Koller
Member
Members
Forum Posts: 3
Member Since:
01/29/2024
sp_UserOfflineSmall Offline
3
01/30/2024 - 04:57
sp_Permalink sp_Print

Hello Randy,

Thanks for your prompt response! 

From your answer I understand that I only need to paste the 4 .DLLs into the GAC for it to work. Is that correct? I believed I had to do something else too, because doing only that does not work for me.

Thanks,
Michael

Avatar
Randy Armstrong
Admin
Forum Posts: 1568
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
01/31/2024 - 02:45
sp_Permalink sp_Print

You do not put anything into the GAC.

Link to the DLLs and it should work.

Avatar
Michael Koller
Member
Members
Forum Posts: 3
Member Since:
01/29/2024
sp_UserOfflineSmall Offline
5
02/02/2024 - 02:30
sp_Permalink sp_Print

Hello Randy

Thanks a lot for your help. It works.

Regards.
Michael

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 35
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1435
Posts: 4862