Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

C# FIT Workout Files

Rank

Total Posts: 2

Joined 2015-11-25

PM

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

Error.png

Click thumbnail to see full-size image

RankRank

Total Posts: 34

Joined 2013-01-28

PM

Hi Stefan, Are you able to send me an example file where it causes the exception? And also send an example of the change that fixes the problem by renaming it? I will PM you with an email to send the files to.      
Rank

Total Posts: 2

Joined 2015-11-25

PM

Thank you Evan

Dont know why my PM does not work but I have emailed you the information.      
RankRank

Total Posts: 34

Joined 2013-01-28

PM

Hi Stefan,

Thanks for sending me your sample code. I understand the problem now and am implementing a fix. We will be doing a public release on Tuesday Dec 1st (16.40), which will have the appropriate fix for this. It appears during some of the work to support the Plugins (FITSDK 16.30) the underlying string support in C# is partially broken. This will address the problems you have seen as well as anyone else having issues with Strings in messages in C#.

-Evan