titanium-as / TitaniumAS.Opc.Client

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

SafeArrayTypeMismatchException #33

Open timverwaal opened 5 years ago

timverwaal commented 5 years ago

Hi all,

using the Matrikon OPC simulation server I can read OPC items easily. It worked like a charm right from the start!

However, I am trying to communicate with an OPC server of another vendor (ABB), and then I get the below exception.

From the stacktrace I can make out that the datatype in the managed code and unmanaged code is not the same or not marshalled correctly (??). But I have not the knowledge nor the expertise so that I can deduce what needs to be altered for this to work.

Can anybody here help me with this? Of push me in the right direction? Any support is much appreciated

Unhandled Exception: System.Runtime.InteropServices.SafeArrayTypeMismatchException: Mismatch has occurred between the runtime type of the array and the sub type recorded in the metadata. at System.Runtime.InteropServices.Marshal.PtrToStructureHelper(IntPtr ptr, Object structure, Boolean allowValueClasses) at System.Runtime.InteropServices.Marshal.PtrToStructure(IntPtr ptr, Type structureType) at TitaniumAS.Opc.Client.Da.Internal.ArrayHelpers.CreateOpcItemResults(OPCITEMDEF[] pItemArray, IntPtr ppAddResults) at TitaniumAS.Opc.Client.Da.Wrappers.OpcItemMgt.<>cDisplayClass5.b4() at TitaniumAS.Opc.Client.Common.ComWrapper.DoComCall[TResult](Object comObject, String methodName, Func1 comAction, Object[] arguments) at TitaniumAS.Opc.Client.Da.Wrappers.OpcItemMgt.AddItems(OPCITEMDEF[] itemDefinitions, HRESULT[]& errors) at TitaniumAS.Opc.Client.Da.OpcDaGroup.AddItems(IList1 itemDefinitions) at OPC_DA_Client.OPCRead..ctor(OpcDaServer opcDaServer) in C:\Users\tverwaal\source\repos\OPC_DA_Client\OPC_DA_Client\OPCRead.cs:line 41 at OPC_DA_Client.OPCProcess.Initialize() in C:\Users\tverwaal\source\repos\OPC_DA_Client\OPC_DA_Client\OPCProcess.cs:line 62 at OPC_DA_Client.Program.RunApplication() in C:\Users\tverwaal\source\repos\OPC_DA_Client\OPC_DA_Client\Program.cs:line 45 at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

Kaliber00 commented 4 years ago

I have the same problem did you find a solution?

Dzuzepppe commented 4 years ago

I have also the same problem (connection to ABB aplication) Someone find a solution for that?

timverwaal commented 4 years ago

I did not find a solution for this problem, so I started using a different repository. https://github.com/hylasoft-usa/h-opc/

Vishnu1221 commented 3 years ago

I am also facing the same issue while working with ABB.AfwOpcDaSurrogate.1 server. It looks like ABB server is not supporting IOPCGroupStateMgt2 interface, is there any way I can force Client app to use IOPCGroupStateMgt. Please try to find the solution ASAP. Or Please suggest me some solution to this problem.

System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'TitaniumAS.Opc.Client.Interop.Da.IOPCGroupStateMgt2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8E368666-D72E-4F78-87ED-647611C61C9F}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'