Web API Error: Failed to serialize the response body for content type


The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.

Just add the following code in WebApiConfig.cs –

var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;

Hope this helps!

Installing multiple versions(32-bit and 64-bit) of Python in Windows

Today we were trying to install multiple versions (or) same version of 32-bit and 64-bit Python in same computer running on Windows 7. After installation, we noticed that it is replacing the previous version after installing the second one. First we installed 64-bit then 32-bit and observed that the system contains only one version of Python that too the latest installed one.

While installing the second version of Python, select the Entire Features will be unavailable under Register Extensions (as shown in the screen-shot below). Continue reading “Installing multiple versions(32-bit and 64-bit) of Python in Windows”

Troubleshooting – Error: Invalid attempt to call HasRows when reader is closed

Usually this error will be encountered while trying to access data from DataReader.

System.InvalidOperationException was unhandled
  Message=”Invalid attempt to call HasRows when reader is closed.”
       at System.Data.SqlClient.SqlDataReader.get_HasRows()

Most of the times the reason will be – you use SqlCnnection object in using block – which will close the connection instance after executing the code in it.
For a DataReader to get data, the connection should be OPEN.

using(SqlConnection sqlConn = new SqlConnection(connectionString))
using (SqlCommand sqlCommand = new SqlCommand())
sqlCommand.Connection = sqlConn;
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = “MY_SP”;
sqlCommand.CommandTimeout = 600;
dataReader= sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);

So, when you try to check HasRows property of the DataReader object  as follows, you will get an error.

if (dataReader !=null && dataReader.HasRows)
while (dataReader.Read())
// your code

The solution for this is

  • DO NOT use SqlConnection in using block
  • DO NOT close the SqlConnection object. Close it using DataReader object as objDataReader.Close();

PropertyAccessor in Exchange 2010 – issue and some workarounds

Following code works fine in Exchange 2003 and 2007. But fails in Exchange 2010, that too in Online Mode. There is an interesting discussion that happened recently in MSDN Forums on this topic. Just would like to share summary of it so that it will be helpful to them who are in need of it.

As of now, there is not work around, except changing mode of Exchange to Cache Mode. Some told that Microsoft is aware of this issue and working on it. A fix may be released with the next patches.

const string TEST_PROPERTY = @"http://schemas.microsoft.com/mapi/string/
 const int TEST_VALUE = 9;
 application = new MSOutlook.ApplicationClass();
 email =
 propertyAccessor = email.PropertyAccessor;
 propertyAccessor.SetProperty(TEST_PROPERTY, TEST_VALUE);
 object objValue = propertyAccessor.GetProperty(TEST_PROPERTY);

Here is another work around suggested by Joel…

“it looks like the it’s not completely resolved by simply using extended MAPI.  I was trying to use IMAPIProps::GetProps() and specifying a single property tag with the ID specified, but the type not specified (using PT_UNSPECIFIED).  As already noted, this works fine with Exchange 2007 online or cached mode, Exchange 2010 in cached mode, but not in Exchange 2010 online mode.

The workaround in this case is to specify the correct property type.  But, since the managed PropertyAccessor.GetProperty() method does not know what the property type is ahead of time (at least for custom properties), I guess that could be why it’s failing.  What I’m doing now is calling IMAPIProp::GetPropList() and finding the entry with matching property tag.  Since GetPropList() returns the property type as well, I can now call GetProps() with the correct property type.  This seems to work in Exchange 2010 online mode :)”

I think this is the simplest of all (which is suggested by Susanne Kapp via Wompi)…

For an easy workaround in VSTO, you can simply call the mailItem.Save() method after setting the property. But be aware of all the mails getting saved to your drafts folder if you don´t send the mail.

Hope this helps!

Troubleshooting Error: Loader Lock was detected

While working with Redemption library, we usually get the following error while debugging the project.

Attempting managed execution inside OS Loader lock. Do not attempt to run
managed code inside a DllMain or image initialization function since doing so
can cause the application to hang.

As per Dmitry Streblechenko (Redemption Team), this exception is raised when .NET thinks that a dll that it is loading is doing something that can potentially lock the loader (like circularly loading dlls etc). Redemption does load the MAPI libraries at the startup, but that is about it. That warning can be safely ignored.



We can skip this error by clearing the LoaderLock checkbox in Debug -> Exceptions -> Managed Debud Assistants.

Debug | Exceptions | Managed Debug Assistants > LoaderLock (Uncheck this!)

Redemption Library is really wonderful creation. It helps the developers a lot in handling and accessing some attributes of Outlook Items which cannot be accessed using the API given by Microsoft.

Error: WriteFile failed => 0x5(5) when Makecert is run


Makecert -sv MyCert.pvk -n”CN=MyCompanyCert” MyCert.cer -b01/01/2009 -e 12/31/2018

While executing the above command, sometimes we get the following error.

Error: WrtieFile failed => 0x5<5>


The solution for this is to run the command prompt in admin mode.

This can be done by right-clicking on the cmd and selecting ‘Run as Administrator‘.
Hope this helps!

Common mistakes while installation and deployment of PIAs

Have you ever came across this error message while deploying PIAs along with your add-in as prerequisites?

Error 1316: Setup cannot read from file {PATH}PIARedist.MSI. Check your connection to the network, or CD-ROM drive. For other potential solutions, see SETUP.CHM.

This error occurs if the PIA’s already installed in the client system. This usually happens with Office 2007 if Outlook is installed with Contact Manager.
Business Contact Manager for Outlook 2007 installs the PIAs by default, and the file name is PIARedist.MSI.  However, the file from the Microsoft Download Center is called o2007pia.msi.  When you install the PIAs from the Microsoft Download Center, this name conflict causes the 1316 error.
The simplest solution is to just ignore the error, because this message means that the PIAs are already installed. If you want to correct the error, uninstall the PIAs through the list of installed programs for the specific computer. Then you can reinstall the PIAs with the Primary Interop Assemblies for the 2007 Microsoft Office system from the Microsoft Download Center.
For more details, refer to Misha’s article in her blog.

Troubleshooting Error – Unable to cast COM object {00063034-0000-0000-C000-000000000046}

Have you ever suffered from the following error while working with COM objects?

Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.Outlook.MailItem’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{00063034-0000-0000-C000-000000000046}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I was a bit clueless why this is occurring even the code is perfect.

Dim fname, email, cname As String
Dim olContactItem As Outlook.ContactItem
Dim ContactsFolder As Outlook.MAPIFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

For i As Integer = 1 To ContactsFolder.Items.Count

If TypeOf (ContactsFolder.Items(i)) Is Outlook.ContactItem Then

olContactItem = ContactsFolder.Items(i)
fname = olContactItem.FirstName
email = olContactItem.Email1Address
cname = olContactItem.CompanyName

End If


Later came to know about the fact that the objects are not released by Garbage Collector even if we call it and nullify the object using Nothing keyword. Here are some points that we need to take care while coding with COM objects like ContactItem, MailItem etc.

  • Declare all objects explicitly and release them each pass through the loop using Marshal.ReleaseComObject()
  • Try using a for() loop rather than a foreach() loop, the foreach() is not only slower but also creates hidden instance variables
  • Make sure no compound dot operators are being used. Instantiate an explicit object for each dot operator, that way you can release them explicitly

Hope this helps!