Main menu

ClickOnce with .Net 4.5.2 Prerequisite installation fail

Recently at Assette, we decided  to improve our product suite by leveraging the power of .Net Framework 4.5.2. so as a first step we wanted to push .Net Framework 4.5.2 to our existing clients using a similar approach mentioned here. ( ClickOnce only allows prerequisites to be installed during the first installation, hence uninstalling and re-installing).

In some machines, especially Windows 7. we started getting the following error message when the setup tried to install .net 4.5.2:

“Setup has detected that the file “<temp path>\NDP452-KB2901954-web.exe” has changed since it was initially published”

Setup has detected that the file "<temp path>\NDP452-KB2901954-web.exe" has changed since it was initially published

Also the log file specified in the above path shows the following: (it says the downloaded DotNetFX452\NDP452-KB2901954-Web.exe is not signed.

Downloading 'DotNetFX452\NDP452-KB2901954-Web.exe' from '' to 'C:\Users\user\AppData\Local\Temp\VSDA23C.tmp\'
Download completed at 10/6/2015 3:23:05 PM
Verifying file integrity of C:\Users\user\AppData\Local\Temp\VSDA23C.tmp\DotNetFX452\NDP452-KB2901954-Web.exe
WinVerifyTrust returned -2146762496
File not signed
Error: Setup has detected that the file 'C:\Users\user\AppData\Local\Temp\VSDA23C.tmp\DotNetFX452\NDP452-KB2901954-Web.exe' has changed since it was initially published.

So after scratching my head a few hours. and some googling figured out some suggestions to add/edit prerequsites by editing the Package.xml file. and i looked at the package.xml file for .net 4.5.2  under “C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages\DotNetFX452\en”

it had the following line that gives the URL of the .net framework web installer:

<String Name="DotNetFX45FullWebBootstrapper">;clcid=0x409</String>

I tried to download the file manually by copying and pasting in the browser and it showed that it has been signed by Microsoft. so just to ensure this is the same URL being downloaded by the setup i ran fiddler and it looked like same for the first instance, it was downloading the below url:

But when i downloaded this url it showed as if the file is not signed. now this is what has been causing the problem for me. looks like the URL that is parsed and not parsed are treated in different manner (&amp; being parsed as &). the one which is not parsed seems to be downloading the signed version of the .net installed and vice versa.

To fix this i simply changed the value for “DotNetFX45FullWebBootstrapper” as below:

<String Name="DotNetFX45FullWebBootstrapper">;amp;clcid=0x409</String>

which in turn when parsed through the setup results in giving the correct url and downloading the right file;clcid=0x409.



SQL 2014 LocalDB Cannot connect

If any of you have the error trying to connect to the SQL Server LocalDB using (localdb)\V12.0. and failed, looks like MS had moved away from numbering the automatic instances and started naming it as “MSSQLLocalDB” so instead of using the above what you have to use is below:


Posted by Microsoft on 5/19/2014 at 11:45 PM
Hi, Thank you for your feedback. In SQL14, we moved away from the numbering/versioning for the automatic instance and named it “MSSQLLocalDB” instead of “v12.0”. The name of the automatic instance in the SQL14 documentation for LocalDB at has been fixed. If you require an instance to be named “v12.0”, you can create a named instance with that name.
Thanks & Regards, Pooja Harjani, Sr. Program Manager, SQL Server, Microsoft. (Source : MS Connect)



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 &gt;= 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&amp;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!!.