why am i getting the error "Unable to cast object of type 'OpcCom.Factory' to type 'Opc.IFactory'."?

StackOverflow https://stackoverflow.com/questions/18236949

  •  24-06-2022
  •  | 
  •  

Frage

I am using the OPC Foundation .NET API, with Visual Studio 2012. When I try to connect I get this error:

Unable to cast object of type 'OpcCom.Factory' to type 'Opc.IFactory'

...at the instruction new Opc.Da.Server( in this code:

private void button1_Click(object sender, EventArgs e)
{
    Opc.Da.Server plcServer = null;

    string serverUrl = "opcda://localhost/RSLinx OPC Server";

    plcServer = new Opc.Da.Server(new OpcCom.Factory(), new Opc.URL(serverUrl));
    plcServer.Connect();
}
War es hilfreich?

Lösung 2

The problem was the version of rslinx i am using, the rslinx installed the opc .net api version 1.3 (i didn't know this) and then i installed the opc .net api 2.0 to make my opc client, so when i added the references i didn't notice that i have 2 versions of the dll's, i only picked the first i saw in the list.

At the end i was using the OpcNetApi.dll 2.0 and the OpcNetApi.Com.dll 1.3. And that's why it was throwing that error.

Andere Tipps

It's throwing this error because the interface for Opc.Da.Server is expecting an Opc.IFactory, but what's returned from OpcCom.Factory() does not implement that interface.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top