In The Mix

As a SharePoint architect I have the business behind me and the Developers and IT Pro on my shoulders.

Serialization inside SandBox Solutions June 29, 2010

Filed under: SharePoint 2010 — fmuntean @ 4:27 pm

When creating a Web Part in SharePoint 2010 that will store configuration/data inside the SP Hierarchical Store at the SPWeb  level, using automatic serialization of an object, I got into the following error: System.Runtime.Serialization.SerializationException was unhandled Message=Unable to find assembly ‘MFD.SandBoxWebPart, Version=, Culture=neutral ….’

Now to explain in more details the problem and how I choose to resolve it.

The configuration class is nothing else than a DTO class containing the configuration items as public properties and the [Serializable] attribute and be as simple as this example:

  1. [Serializable]
  2. public class MyConfig
  3. {
  4.     public string Config1 { get; set; }
  5.     public long Config2 { get; set; }
  6. }

I got the previous error when adding an instance of this class into the SPWeb Properties as in the following example (the exception gets thrown at line 5):

  1. SPWeb web = SPContext.Current.Web;
  2. {
  3.     var config = new MyConfig()
  4.                     {Config1=“Value1”,Config2=123};
  5.     web.AddProperty(“Key”,config);
  6. }

Now there is nothing wrong with accessing the SPWeb properties inside the Sandbox solutions as the following code will work just fine:


The problem is that the serialization mechanism inside .NET requires to load the assembly for reflection. The SandBox assembly can’t be found because it is not saved in the GAC or any of the SharePoint folders as it only resides in memory and on the Content Database.

A work around for this to create your own serialization to xml/string using custom methods that will save/restore your data using one of the .NET classes (that can be serialized because they live in GAC).

An example of new MyConfig class will look like this:

  1. [Serializable]
  2. public class MyConfig
  3. {
  4.     public string Config1 { get; set; }
  5.     public long Config2 { get; set; }
  6.     public static MyConfig FromXML(string xml)
  7.     {
  8.         XElement doc = XElement.Parse(xml);
  9.         return new MyConfig()
  10.         {
  11.             Config1= doc.Element(“Config1”).Value,
  12.             Config2 = long.Parse(doc.Element(“Config2”).Value)
  13.         };
  14.     }
  15.      public string ToXml()
  16.         {
  17.             XElement xml = new XElement(“MyConfig”,
  18.                 new XElement(“Config1”,this.Config1),
  19.                 new XElement(“Config2”,this.Config2));
  20.             return xml.ToString();
  21.         }
  22. }

Now all you have to do to store the config in SPWeb properties is to:

  1. SPWeb web = SPContext.Current.Web;
  2. {
  3.     var config = new MyConfig()
  4.                     {Config1=“Value1”,Config2=123};
  5.     web.AddProperty(“Key”,config.ToXML());
  6. }

Moving your boot from VHD to a bigger drive June 27, 2010

Filed under: Uncategorized — fmuntean @ 4:46 pm

The most important thing when using boot to VHD is that all your system files are located into a single VHD file on your physical HDD. This will let us easily upgrade the HDD by copying the VHD file from one to another then fix the boot for the new HDD.

Following are the detailed steps to accomplish this:

Attach the new HDD as an external one or as a second one if your computer permits.

Server Manager -> Storage -> Disk Management

New Simple Volume (format NFTS, quick) mount as f:

Mark Partition as Active

Command prompt

Bcdboot c:\windows /s f:

Bcdedit /export f:\backup.bcd


Boot from Win7 or Windows 2008R2 DVD

After "windows loading files…" message when the initial setup screen is displayed press SHIFT+F10 for command prompt

Copy vhd file from old disk to new one (you need to find the drive letters again as they might not match)


C: is the internal HDD

D: is the DVD

E: is the external HDD

Xcopy /J c:\win2k8R2.vhd e:\ (wait… it will take a while)

NOTE: Or you can copy now the entire hard drive including the hidden folders using xcopy /H

I am only copy the vhd so I can get my computer up and running faster then I will copy the rest of the file later in background.

Close command prompt -> cancel installation (ALT+F4) -> shutdown the machine

Remove old hard drive and replace with the new one.

Start computer.

Boot from install DVD again and start the command prompt

Bcdedit /import c:\backup.bcd

Fix the entry

Bcdedit /set {default} device vhd=[LOCATE]\win2k8R2.vhd

Bcdedit /set {default} osdevice vhd=[LOCATE]\win2k8R2.vhd

Reboot and



No SharePoint Conference in 2010 ? June 8, 2010

Filed under: Conference — fmuntean @ 6:25 pm

Today I have got an email announcing the SharePoint  Conference which I attended for the last few years now. I got so exited and tried to register but for my surprise the conference starts only in October of 2011.

Hmm. What is going on?

Microsoft ships SharePoint 2010, which is a big improvement over the “old”  MOSS 2007, but skips the most important conference for SharePointers this year?

I was prepared to attend all the 400 level sessions available, to gain as much knowledge as I can from the experts. I have been part of the SharePoint 2010 Ignite training and been to SPC2009 in October of last year, and I still consider that there is a lot more for me to learn about this new platform.


If you are interested into getting more info in a certain area of SharePoint please feel free to contact me and maybe we can have our own mini-conference.