I am doing some workout files for Garmin devices in C# / VB.net. Everything works fine but on some of my workout step names it seems to bomb out. I get the attached error. If I change the names to random stuff it runs through without any problems.
It comes from the following code. As soon as the field size is smaller than the fielddefsize it throws adds a non byte value.
while (field.GetSize() < fieldDef.Size)
{
field.AddValue(Fit.BaseType[fieldDef.Type & Fit.BaseTypeNumMask].invalidValue);
}
The error occurs in the following piece off code inside the for each loop.
"An unhandled exception of type 'System.InvalidCastException' occurred in Fit.dll
Additional information: Unable to cast object of type 'System.Byte' to type 'System.Byte[]'."
public byte GetSize()
{
byte size = 0;
switch (Type & Fit.BaseTypeNumMask)
{
case Fit.Enum:
case Fit.SInt8:
case Fit.UInt8:
case Fit.SInt16:
case Fit.UInt16:
case Fit.SInt32:
case Fit.UInt32:
case Fit.Float32:
case Fit.Float64:
case Fit.UInt8z:
case Fit.UInt16z:
case Fit.UInt32z:
case Fit.Byte:
size = (byte)(GetNumValues() * Fit.BaseType[Type & Fit.BaseTypeNumMask].size);
break;
case Fit.String:
// Each string may be of differing length
// The fit binary must also include a null terminator
foreach (byte[] element in values)
{
size += (byte)(element.Length + 1);
}
break;
default:
break;
}
return size;
}
Image Attachments
Click thumbnail to see full-size image