Second Life of a Hungarian SharePoint Geek

May 18, 2010

SharePointConnectionException when executing a SharePoint command

Filed under: SP 2010, VSX — Tags: , — Peter Holpar @ 02:16

The other day I developed a custom SharePoint command in Visual Studio 2010.

I was to specify a String parameter for the command and it should have returned a simple .NET object having a few properties. Something like that:

  1. using System;
  3. namespace MyNameSpace
  4. {
  5.     public class MyClass
  6.     {
  7.         public String Title { get; set; }
  8.         public bool IsDeleted { get; set; }
  9.     }
  10. }

To execute the command that returns this kind of data I had to use the following overload of the ExecuteCommand method:

TResult ExecuteCommand<T, TResult>(string commandId, T arg)

It seemed that the command was executed successfully, but I experienced that instead of the expected result, an exotic runtime exception was generated:

Microsoft.VisualStudio.SharePoint.SharePointConnectionException. Message: Type ‘MyNameSpace.MyClass’ with data contract name ‘MyClass:’ is not expected. Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

I used this type of ExecuteMethod successfully for simple object types, like String.

The following posts gave me some info on the possible background of the error:

All About KnownTypes
About KnownTypeAttribute example

Finally, I found a rather simple and logic solution for the issue:

  1. using System;
  2. using System.Runtime.Serialization;
  4. namespace MyNameSpace
  5. {
  6.     [Serializable()]
  7.     public class MyClass
  8.     {
  9.         public String Title { get; set; }
  10.         public bool IsDeleted { get; set; }
  11.     }
  12. }

It seems the object must be serializable to be transmitted over the wire. It is interesting that if I use a similar “complex” object type as the input parameter of the ExecuteMethod, it runs without error, even if the class is not serializable.


1 Comment »

  1. […] The class is decorated with the Serializable attribute. I discussed that issue in my former post. […]

    Pingback by Visual Studio 2010 extension for helping SharePoint 2010 debugging « Second Life of a Hungarian SharePoint Geek — May 20, 2010 @ 01:04

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: