- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-02-21 04:22 AM . Last Modified: 2023-05-02 11:58 PM
Load History using automation interface by C#
Hello Everyone,
We're trying to load history data using C# following this link
Solved: Using automation interface with C# to load history - Communities (se.com)
but an exception was thrown
Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Our Code:
ScxV6Server Svr = new ScxV6DbClient.ScxV6Server();
Svr.Connect("xxx", "xx", "xxx");
ScxV6Object csObj = Svr.FindObject("xxx");
object Historic = csObj.Interface.GetType().InvokeMember("Historic", System.Reflection.BindingFlags.GetProperty, null, csObj.Interface, null);
if (Historic != null) {
Historic.GetType().InvokeMember("LoadDataValue", System.Reflection.BindingFlags.InvokeMethod, null, Historic, new Object[] { 1, 192, "2022-02-21 10:09:05", 48.2 }); // the exception thrown at this line
}
Svr.Disconnect();
any help appreciated
- Labels:
-
SCADA
Link copied. Please paste this link to share this article on your social media post.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-02-21 04:31 AM
In the arguments to the LoadDataValue method you've used a string for the time, which is the wrong type and likely the cause of the type mismatch exception.
You should use a System.DateTimeOffset for times:
https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset?view=netframework-4.8
Andrew Scott, R&D Principal Technologist, AVEVA
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-02-21 04:52 AM
We've replaced with DateTime and it worked just fine
string t = (DateTime.Now.ToString());
Historic.GetType().InvokeMember("LoadDataValue", System.Reflection.BindingFlags.InvokeMethod, null, Historic, new Object[] { 1, 192, t, 148.12 });
thanks
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-02-21 04:31 AM
In the arguments to the LoadDataValue method you've used a string for the time, which is the wrong type and likely the cause of the type mismatch exception.
You should use a System.DateTimeOffset for times:
https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset?view=netframework-4.8
Andrew Scott, R&D Principal Technologist, AVEVA
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-02-21 04:39 AM
We've changed the time as suggested
Historic.GetType().InvokeMember("LoadDataValue", System.Reflection.BindingFlags.InvokeMethod, null, Historic, new Object[] { 1, 192, DateTimeOffset.Now, 48.2 });
another exception where thrown
Exception Details: System.ArgumentException: Value does not fall within the expected range.
any hint
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-02-21 04:52 AM
We've replaced with DateTime and it worked just fine
string t = (DateTime.Now.ToString());
Historic.GetType().InvokeMember("LoadDataValue", System.Reflection.BindingFlags.InvokeMethod, null, Historic, new Object[] { 1, 192, t, 148.12 });
thanks
Link copied. Please paste this link to share this article on your social media post.

