Add List of OwnClass

Posted by: jonigk on 14 January 2020, 12:01 am EST

  • Posted 14 January 2020, 12:01 am EST

    HI, we are using spread winforms v12.45.20193.0.
    Currently it´s not possible to add a List of own classes at Sheet.Tag Propery.


    [Serializable]
    public class MyClass
    {
    // some Properties
    }

    public void Spread_SpreadStart()
    {
    FarPoint.Win.Spread.SheetView newSheet = new FarPoint.Win.Spread.SheetView();

    newSheet.Tag = new List<string>(); // working
    newSheet.Tag = new List<DateTime>(); // working
    newSheet.Tag = new List<FarPoint.Win.Spread.PrintHeader>(); // working

    newSheet.Tag = new List<MyClass>(); // not working

    this.Spread.Sheets.Add(newSheet);
    }

    Error:

    The type System.Collections.Generic.List`1[[SpreadScript+MyClass, 2deaamg3, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] in assembly FarPoint.Win.Spread, Version=12.45.20193.0, Culture=neutral, PublicKeyToken=327c3516b1b18457 could not be found


    Best Regards,
    Sven
  • Replied 14 January 2020, 4:57 pm EST

    Hi Sven,

    I could not observe any issue when using your given code. Please see the attached sample and make any necessary modifications so we can replicate it at our end and investigate it further.

    SheetTag_CustomClass.zip

    Thanks,
    Jitender
  • Replied 20 January 2020, 7:03 pm EST

    Hi Jitender,
    thanks for your reply.
    i also could not reproduce the error with your stand alone project. :-(

    I attached the stack trace.

    meanwhile we did a workaround an put the List in a new object, which worked fine


    [Serializable]
    public class MyClass
    {
    public int Number { get; set; }
    }

    [Serializable]
    public class MyClassList
    {
    public List<MyClass>MyList { get; set; }
    }

    //Wird vor dem Erzeugen der Tabellenkalkulation ausgeführt
    public void Spread_SpreadStart()
    {
    this.Spread.ActiveSheet.Tag = new MyClassList ()
    {
    MyList = new List<MyClass>()
    };
    }


    System.TypeLoadException: The type System.Collections.Generic.List`1[[SpreadScript+MyClass, or1r4fuf, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] in assembly FarPoint.Win.Spread, Version=12.45.20193.0, Culture=neutral, PublicKeyToken=327c3516b1b18457 could not be found.

    bei FarPoint.Win.Spread.Model.SpreadSerializer.OpenXml(FpSpread spread, Stream stream)

    bei FarPoint.Win.Spread.FpSpread.Open(Stream stream)
  • Replied 22 January 2020, 6:14 pm EST

    Hi Sven,

    From your stacktrace it seems that you are loading Spread from an XML file. If it's possible, can you also show us the XML file or a small sample where we can observe this?

    Thanks,
    Jitender
  • Replied 27 January 2020, 12:18 am EST

    Hi Jitender,
    i attached the xml file.
    The script is saved in our database and will be loaded / compliled during loading process.
  • Replied 27 January 2020, 5:06 pm EST

    Hi,

    It seems the file was not attached.
    Make sure to first archive the XML file to .zip file since only images and zip files can be attached here.

    Regards,
    Jitender
  • Replied 27 January 2020, 8:19 pm EST

    Hi Jitender,
    didn't see the hint yesterday, sorry.
    I have now uploaded it as a zip file

    MyClass-Example.zip
  • Marked as Answer

    Replied 27 January 2020, 9:26 pm EST

    Hi,

    Your XML file had no mention of 'MyClass'. However, I was able to reproduce your scenario.
    Here's what I did:
    1. Create an instance of FpSpread, add a sheet with its Tag property set to List<MyClass>.
    2. Save this instance to an XML file.
    3. Comment-out the definition of MyClass.
    4. Open the saved XML file with an instance of FpSpread.

    In this case, as the exception says Spread is unable to find the type 'MyClass'. Maybe, the definition of 'MyClass' is not available when you're opening the XML file?
    But your workaround somehow works so I'm not sure but this error is encountered when the definition of a Type is not available.

    Do you also observe this exception when loading the file in a separate project? If yes, then please create a small sample so we can look into it.

    Thanks,
    Jitender
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels