diff --git a/S7.Net/Protocol/Serialization.cs b/S7.Net/Protocol/Serialization.cs
index 3ecee55..b9ac9a5 100644
--- a/S7.Net/Protocol/Serialization.cs
+++ b/S7.Net/Protocol/Serialization.cs
@@ -13,6 +13,10 @@ namespace S7.Net.Protocol
public static byte[] SerializeDataItem(DataItem dataItem)
{
+ if (dataItem.Value == null)
+ {
+ throw new Exception($"DataItem.Value is null, cannot serialize. StartAddr={dataItem.StartByteAdr} VarType={dataItem.VarType}");
+ }
if (dataItem.Value is string s)
return dataItem.VarType == VarType.StringEx
? StringEx.ToByteArray(s, dataItem.Count)
diff --git a/S7.Net/Types/TypeHelper.cs b/S7.Net/Types/TypeHelper.cs
index 983299b..af5441b 100644
--- a/S7.Net/Types/TypeHelper.cs
+++ b/S7.Net/Types/TypeHelper.cs
@@ -24,7 +24,7 @@ namespace S7.Net.Types
///
/// Converts an array of T repesented as S7 binary data to an array of T
///
- public static T[] ToArray(byte[] bytes, Func converter)
+ public static T[] ToArray(byte[] bytes, Func converter) where T : struct
{
var typeSize = Marshal.SizeOf(default(T));
var entries = bytes.Length / typeSize;