Main menu

How to: Programmatically Re-enable an Add-in That Has Been Disabled (VSTO)

Microsoft Office applications can disable add-ins that behave unexpectedly. If an application does not load your add-in when you try to debug it, the application might have hard disabled or soft disabled your add-in.- MSDN.

To enable the Add-in back via the office application you have to follow whats mentioned in this link.

Programmatically Enabling Soft Disabled Add-ins

Soft disabling can occur when an add-in produces an error that does not cause the application to unexpectedly close. For example, an application might soft disable an add-in if it throws an unhandled exception while the Startup event handler is executing.

Now lets see how we can enable this programmatically. for the sample I’m using PowerPoint.


            PowerPoint._Application app = null;
            app = Marshal.GetActiveObject("PowerPoint.Application") as PowerPoint._Application;
            object index = "your app";
            COMAddIn addin = null;
            addin = app.COMAddIns.Item(ref index);
            if (addin.Connect)
                addin.Connect = true;

Programmatically Enabling Hard Disabled Add-ins

Hard disabling can occur when an add-in causes the application to close unexpectedly. It might also occur on your development computer if you stop the debugger while the Startup event handler in your add-in is executing.

To enable add-ins that are Hard disabled you might have to play a little with registry. specifically the registry entry at :


Basically your add-in should have an entry here. and its value is in binary format. if you delete the entry it might enable you add-in again. but blindly deleting all entries might enable any other add-ins too. mostly this binary value will contain the application path (ClickOnce Url or the installation path) encoded. to specifically delete your add-in you might have to do the following :


    var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\15.0\PowerPoint\Resiliency\DisabledItems", true);
            var names = key.GetValueNames();
            foreach (var item in names)
                var valueKind = key.GetValueKind(item);
                if (valueKind == RegistryValueKind.Binary)
                    var regValue = (byte[])key.GetValue(item);
                    BinaryReader binaryReader = new BinaryReader(new MemoryStream(regValue));
                    int pathLength = binaryReader.ReadInt32(); // The next four bytes are the length of the path
                    if (regValue.Length >= 12 + pathLength)
                        string path = Encoding.Unicode.GetString(regValue, 12, pathLength - 2);
                        if (path.ToLower().Contains("your application path"))// something to uniquely identify your application

(Note: office application version and application name might be different based on your office add-in).

For detailed information on  VSTO Add-in loading issues please refer this link.

To turn off document recovery refer this post.

.Hope it helps :).

Error loading type library/DLL (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))


Well well.. here is another headache for those who automate office:

System.InvalidCastException: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.PowerPoint.Application’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{91493442-5A91-11CF-8700-00AA0060263B}’ failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)

note: the application highlighted above could be any office application. after cracking my head, re installing office, and some googling. found out the solution here.

also the post here in MSDN gives some good insight about the problem too.

Hope it helps.

After 2 years from my last post

Hmm.. its been almost 2 years since i last blogged. lots of things happened around me,  from a happy role change in my career, to things that turned my life upside down, my dad was diagnosed for oral cancer in late 2011, and the sudden demise of him on ~2,15am 31st of March 2012 (I still miss him!!). which i almost lost focus on blogging and .net community activities.


And here i’am trying to come back!.

As for last 2 years i’ve been focusing on iOS development, VSTO, MVC, ASP.Net 4, WPF and OpenXml mainly. hope i could share my experience on these stuff in my future posts.




My Presentation on ASP.Net WebMatrix for .Net User Group Meeting.

Last Thursday i did a presentation on ASP.Net WebMatrix in the .Net User Group meeting held in Colombo.  so thought of  sharing the presentation with you all. there were some code demos also, but unfortunately i couldn’t upload them. if anyone is interested you can download and view the presentation in the link below or view it in the Scribd document.

I must thank Joe Stagner from microsoft for his ScreenCasts and Presentation on WebMatrix, which were very helpful for me to prepare my presentation too.

Introduction to ASP.Net Webmatrix

Download the Slide Deck here



Youtube Helper for ASP.Net WebMatrix [UPDATED For Beta 2]


ASP.Net WebMatrix is a lightweight web development tool that contains IIS Express, SQL CE 4.0 and ASP.Net Web Pages with Razor Syntax. to learn more about ASP.Net WebMatrix read this excellent tutorial.

The ASP.Net Web pages ships with some really cool helpers like easy database access, Twitter profile, & Facebook like button.  and it also allows us to create our own helpers. in the current beta release of the WebMatrix there are 2 ways to create a helper:

  1. Using a visual studio class library (Recommended).
  2. Use .cs file in the App_Code directory in the WebMatrix project folder.

In this post I’m going to show you how to create a Helper to add Youtube Videos to your WebMatrix pages. as you know a helper needs to be a static class. here is the code:

using System;
using System.Web;
using System.Web.Mvc; 
using System.Web.WebPages;
using System.Web.Helpers;
public static class MyHelpers
    public static IHtmlString Youtube(string link, int width = 480, int height = 385, bool allowFullScreen = true)
        string innerHtml = string.Empty;
        var url = "{0}?fs=1&hl=en_US";
        //prepare video embed URL
        var uri = new Uri(link);
        var querystring = uri.Query;
        var videoCode = HttpUtility.ParseQueryString(querystring).Get("v");
        url = string.Format(url, videoCode);
        //prepare HTML
        var html = new TagBuilder("object");
        html.MergeAttribute("width", width.ToString(), true);
        html.MergeAttribute("height", height.ToString(), true);
        var param1 = new TagBuilder("param");
        param1.MergeAttribute("name", "movie", true);
        param1.MergeAttribute("value", url, true);
        var param2 = new TagBuilder("param");
        param2.MergeAttribute("name", "allowFullScreen", true);
        param2.MergeAttribute("value", allowFullScreen.ToString(), true);
        var param3 = new TagBuilder("param");
        param3.MergeAttribute("name", "allowscriptaccess", true);
        param3.MergeAttribute("value", "always", true);
        var embed = new TagBuilder("embed");
        embed.MergeAttribute("src", url, true);
        embed.MergeAttribute("type", "application/x-shockwave-flash", true);
        embed.MergeAttribute("allowscriptaccess", "always", true);
        embed.MergeAttribute("allowfullscreen", allowFullScreen.ToString(), true);
        embed.MergeAttribute("width", width.ToString(), true);
        embed.MergeAttribute("height", height.ToString(), true);
        innerHtml += param1.ToString(TagRenderMode.SelfClosing);
        innerHtml += param2.ToString(TagRenderMode.SelfClosing);
        innerHtml += param3.ToString(TagRenderMode.SelfClosing);
        innerHtml += embed.ToString(TagRenderMode.SelfClosing);
        html.InnerHtml = innerHtml;
        return new HtmlString(html.ToString(TagRenderMode.Normal));

Few things to note in the above code.  i have referenced System.Web.Mvc to use the TagBuilder to create safe html, and System.Web.Helpers to create the helper. the second one, you can find in C:\program files\Microsfoft ASP.Net (or installation directory).

And I’m using the System.Web.HttpUtility here to extract a query string from a Uri.

        //prepare video embed URL
        var uri = new Uri(link);
        var querystring = uri.Query;
        var videoCode = HttpUtility.ParseQueryString(querystring).Get("v");

I use the above code to convert the Youtube public link to the actual video link.

And since my code needs to return an html which should not be html encoded again. my methods return type is IHtmlstring. using this tells the ASP.Net pages not to encoded this html again, as this is already encoded.

Now create the folder App_Code in your WebMatrix Project, and create a file named MyHelpers.cs and paste the code above in that.

Now you can use this in your WebPages like this to embed youtube videos in your pages:


Other parameters such as width,height are optional as you can notice we have used optional parameters.

UPDATES for beta 2:

  1. In beta 1 WebPages were in Microsoft.WebPages. but in WebMatrix beta 2 its moved to System.Web.WebPages
  2. I had to copy System.Web.Mvc.dll to the bin directory of WebMatrix project to make this workin in WebMatrix beta 2.

I Hope it helps


Fix: .Net 2.0 or 3.5 Setup Project Requires .Net Framework version 4.0

Sorry again folks again I was MIA with loads and loads of work. trust me i have more than 30 drafts which i started and never got time to finish. anyway coming to the point this morning i was trying to deploy a windows service project using the setup project templates in visual studio 2010, and when i tried to install it on client machine i got the following message:

The Setup Requires the .Net Framework version 4.0

But I’m pretty sure that i had the project targeted to .net Framework 3.5 SP1, but still it was  requiring .net 4.0.  as usual i did a Google search and found this article with the trick to resolve it.

actually it was the dependencies in the setup project causing the issue, it was still targetting 4.0 even though my application targets .net 3.5 and by default VS2010 set the dependency to .Net 4.0.

if you have this issue all you have to do is the following :

  1. Double click on the dependencies of the setup project.
  2. Click on the .Net Framework
  3. And you will see the Property window will get enabled.
  4. Change the Version property to your desired .net Framework ( in my case 3.5).
  5. and build your setup again.

That’s it :).

for the original article that gave me this solution visit here.

Just thought i would share this information which that might be helpful for those developers who are in migration process to VS2010 :). hope it help guys!!.



Visual Studio 2010 RTM & .Net framework 4.0 Final version released

Its been a long time i wrote something on my blog, thanks to my busy work schedule i have a large number of drafts saved lolz. this is just a quick post

Anyway today is another big day for .Net developers around the world, yeah the final version of visual studio 2010 is released.  visual studio 2010 is the next major  version of its predecessor with loads of new features.

if you want to see the launch event of visual studio you can see it here.

Scott Guthrie, and other geeks from microsoft tweeted that visual studio will be available for download around 10 am (PST).  and the good news is its available for the websitespark subscribers too :)

here are some of those tweets for you :

@shanselman: Developers: MSDN will be updated with #vs2010 downloads and details at 10am PST *today*! Pls RT! 

@scottgu:MSDN Subscribers & WebsiteSpark/BizSpark members can download VS 2010 Monday morning.

happy developing guys :)

Visual Studio 2010 RC Now Available for Download

Microsoft has just released the Release Candidate version of Visual Studio 2010 for public download. You can now download and try out Visual Studio 2010 RC and .NET Framework 4 RC before the final version which is due to hit retail in this first quarter of 2010. It was released for MSDN Subscribers on 8th February and released for the public just few minutes ago (11th February 2010).

Visual studio 2010 RC

It is a much  awaited version of visual studio and it is available in following SKU’s:

  • Visual Studio 2010 Ultimate
  • Visual Studio 2010 Premium
  • Visual Studio 2010 Professional

Those who wish to try it, go get your copy here.

According to the reviews so far VS 2010 RC seems to be much faster in  Compiling, Building  and Intellisense. Read Scott Guthrie’s announcement on this release here.