MongoDB Import JSON Error – Unmarshalling Bytes

While importing data from a JSON file into MongoDB using following command  –

mongoimport --db my_db --collection my_collection --file json_file.json

if you encounter following error –

Failed: error unmarshaling bytes on document #0: JSON decoder out of sync - data changing underfoot?

Mos probable reason is some parts of JSON Objects are not properly formatted. For that you need to use –jsonArray flag with the command.

mongoimport --db my_db --collection my_collection --file json_file.json --jsonArray

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 = @"
 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!

800704a6 Error while opening JavaScript driven pages in IE8 – Work arounds

In my project, there is a WebBrowser Control in a form. It opens a webpage dynamically which in-turn opens an IE popup using Window.Open() during OnLoad and this window closes after opening the popup.
This is the functionality and it worked fine since last 8 months with IE6 and and IE7. But, now when I am doing the same with IE8 on Windows XP, I got a JS Error and that MessageBox showed me the error as:

Line: 1
Char: 1
Error: Could not complete the operation due to error 800704a6.

As usual, started googling about the topic and found some interesting links. Here is a consolidated work-arounds for the problem from various sources.
First of all, it really matters what mode you are in. In IE8, there are 3 (THREE) modes.

  • IE5 Quirks – your page has no doctype, page renders like IE5 did
  • IE 7 Standards Mode – you have a doctype, but either opted out of IE8 standards mode, or are running on localhost, or in “Compatibility Mode”
  • IE 8 Standards Mode – you have a doctype, and are on the INTRANET (default mode)

Now, if you are rendering in IE5/IE7 mode, then Nothing changes except that there will be a few methods added that shouldn’t interfere with your page.
However, if like the majority, you are running with a doctype set, and thus in IE8 Standards mode, the following changes have occurred.

  1. document.getElementById( id ); //now only returns the CORRECT matches!
  2. .getElementsByName( name ); //now only returns the CORRECT matches!
  3. .getAttribute( name ); //returns the CORRECT value for the given attribute!
  4. .setAttribute( name, value ); //actually SETS the name/value CORRECTLY (no more cAmElCaSe crud)!
  5. CSS Expressions are NO LONGER allowed (deprecated)
  6. Operation Aborted errors will still be thrown (in some cases) however the cases are fewer, and the error won’t kill the entire page/DOM
  7. The attributes[] array on elements should (from the RC build onwards) be correct in terms of contents, have a length, etc.
  8. Button elements now submit the contents of the value attribute, NOT the HTML contents of the Button Tag

There has also been a bunch of CSS 2.1 fixes, so things that rendered weird before, or needed hacks, should be much better. (see below for details on alpha/transparency – there’s been big changes)
See the IE Blog for details.
Also see Web Bug Track for fine grained details on Bugs, Fixes for IE8 (and all other browsers)
SVG, rounded corners, ECMAScript based Event Listeners, Better Form Element design/events etc. are still missing.
A quick work-around is as follows. (If the problem is with security settings, we can get an instant solution by setting up the following values)
Go to Tools-> Internet Options-> Security and click on ‘Custom Level…’ (in the Security level for this zone group)
Under the Miscellaneous section:
Use Pop-up Blocker (disable)
Under the Scripting section:
Active Scripting (enable)
Allow status bar updates via script (enable)
Allow Websites to Prompt for infomation… (Enable)
Enable XSS filter (Enable)
Under the section User Authentication:
Logon (Anonymous logon)
Or else we can try by unchecking the Enable Protected Mode from the following window.
Menu Tools -> Internet Options -> Security -> Internet -> Enable Protected Mode (Uncheck it)
If you are aware of any other work-arounds please let us know by posting in the comments section.
Hope this helps.
Thank you!