【问题标题】:why am i getting the error "Unable to cast object of type 'OpcCom.Factory' to type 'Opc.IFactory'."?为什么我收到错误“无法将'OpcCom.Factory'类型的对象转换为'Opc.IFactory'。”?
【发布时间】:2013-08-14 16:12:51
【问题描述】:

我在 Visual Studio 2012 中使用 OPC Foundation .NET API。当我尝试连接时,我收到此错误:

无法将“OpcCom.Factory”类型的对象转换为“Opc.IFactory”类型

...在此代码中的指令new Opc.Da.Server(

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();
}

【问题讨论】:

    标签: c# .net opc


    【解决方案1】:

    它抛出这个错误是因为Opc.Da.Server 的接口需要一个Opc.IFactory,但从OpcCom.Factory() 返回的内容没有实现该接口。

    【讨论】:

      【解决方案2】:

      问题是我使用的 rslinx 版本,rslinx 安装了 opc .net api 1.3 版(我不知道),然后我安装了 opc .net api 2.0 来制作我的 opc 客户端,所以当我添加了我没有注意到我有 2 个版本的 dll 的引用,我只选择了我在列表中看到的第一个。

      最后我使用的是 OpcNetApi.dll 2.0 和 OpcNetApi.Com.dll 1.3。这就是它抛出该错误的原因。

      【讨论】:

        猜你喜欢
        • 2015-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-04
        • 1970-01-01
        相关资源
        最近更新 更多