0

I'm trying to port a farm solution to a sandboxed one, and I can't figure out how to port this piece of code:

[ToolboxItem(false)]
public partial class vClockPartSB : System.Web.UI.WebControls.WebParts.WebPart
{
    [Personalizable(PersonalizationScope.User)]
    public Collection<String> ClockTimeZones { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public int NumberOfClocks { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlMain { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubOne { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubTwo { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubThree { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubFour { get; set; }



    protected override void OnInit(EventArgs e)
    {
        ClockTimeZones = new Collection<string>();
        base.OnInit(e);
        InitializeControl();
    }

I get the following error:

Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: Web part property 'ClockTimeZones' uses unsupported type (System.Collections.ObjectModel.Collection`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]), and cannot be run as a sandboxed code web part.

How should I approach it?

  • And what about using a simple List<string> instead of Collection? – Ruben Herman Jul 31 '12 at 12:53
  • Same. Also with a simple array. – Rafał Saltarski Jul 31 '12 at 12:56
1

I would be tempted just to store a string - rather than a collection of strings - and perform my own serialisation/deserialisation. Probably using the string.Split() function and a suitable delimiter.

0

The System.Collections.ObjectModel namespace is not allowed in the Sandbox.

For your scenario, could you use the List< string > instead?

0

Apparently, only the following types are supported as the properties of the web part in the sandbox solution:

  • string
  • bool
  • Enum
  • short
  • int
  • Guid
  • Uri
  • byte
  • char
  • long
  • float
  • decimal
  • double

Here is a link to Alan Dahl's blog article where Alan Dahls' blog did the search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.