Knowing How the Sandbox Changes the Object Model in SharePoint 2010

I ran across a weird little problem last week and thought I would share the resolution. I have a feeling this may be blogged about / documented somewhere and if so then I guess this is just more fuel for the fire.

I was working on a sandbox solution and in particular one of the properties of the SPSite class. I really thought the property should not be settable in the sandbox but my basic investigation did not seem to suggest it was read-only. Usually I start with a tooltip and it will say "Gets or sets blah" if it is is read write, and just "Gets blah" if it is read only. Well there was no tooltip on this particular property other than the data type. So, I tried assigning a value to the property and compiling, thinking that it would catch a read-only property set. No such luck. I also checked the SharePoint SDK and it showed that the property is read / write and in the sandbox, so at that point I assumed it was read / write.

Well, as you can probably guess by now, it turns out the property IS read only, I just didn't figure it out. Many thanks to Matt S. for telling me the right way to track this down in the future. In Visual Studio open up the Object Browser. Next to the Browse: drop down on top is a button with an ellipses (...). Click that button and then click the Browse tab. Navigate to the SharePoint installation directory, then browse ot the UserCode\assemblies directory. Add the Microsoft.SharePoint.dll assembly from that directory; one of the ways that you can tell that it's the sandbox version of the assembly is that the version is 14.900, where as the full Microsoft.SharePoint assembly is version 14.0. After you add that assembly you can cruise only through the part of the object model that is exposed via the sandbox. You can also click on any individual property and see whether it is read-write or read-only in the sandbox. This is a nice little development troubleshooting tip.