Creating public properties in sandboxed webpart solutions
-
09-12-2019 - |
Question
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?
Solution
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.
OTHER TIPS
The System.Collections.ObjectModel
namespace is not allowed in the Sandbox.
For your scenario, could you use the List< string > instead?
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.