RSS

ClickOnce Application,Expired Certificates & Public Key Token PART II

Thu, Jun 11, 2009

View Comments

In the first part of this series I wrote the possible solutions available for the ClicOnce certificate issue. if you have missed it please read it before continuing.

        This post is not going to be a long one, I  just want to point out a very important issue, when updating the ClickOnce using the method specified in PART I .
        When using Jim Harte’s Method to update a ClickOnce with a new certificate, it checks for the public token key of the current application to find its uninstall string, and then execute runDLL32 to trigger the uninstall. below is the code which gets the uninstall string:
          /// <summary>
          /// Gets the uninstall string for the current ClickOnce app from the Windows 
          /// Registry.
          /// </summary>
          /// <param name="PublicKeyToken">The public key token of the app.</param>
          /// <returns>The command line to execute that will uninstall the app.</returns>
           private static string GetUninstallString(string PublicKeyToken,
                                    out string DisplayName)
          {
           string uninstallString = null;
           string searchString = "PublicKeyToken=" + PublicKeyToken;
           RegistryKey uninstallKey = _
                Registry.CurrentUser.OpenSubKey
                          ("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
           string[] appKeyNames = uninstallKey.GetSubKeyNames();
           DisplayName = null;
           foreach(string appKeyName in appKeyNames)
          {
            RegistryKey appKey = uninstallKey.OpenSubKey(appKeyName);
            uninstallString = (string)appKey.GetValue("UninstallString");
            DisplayName = (string)appKey.GetValue("DisplayName");
            appKey.Close();
          
           if(uninstallString.Contains(searchString))
                              break;
           }
                      uninstallKey.Close();
                      return uninstallString;
                  }
           

           

          In the above code it goes through registry keys of all ClickOnce application to get the uninstall string. and if that uninstall string contains the Public Token key of the current application, it will uninstall the application with that particular uninstall string. this is completely ok if there is only one application with that public token key. the public key of an assembly name identifies the developer (or the organization). Most organizations use only one public key to sign their assemblies with. so what if there is more than 1 application which has the same public token key?

      • The code will uninstall the very first match in the above code and it might uninstall some other application, instead of uninstalling the one we need to uninstall.
      • and it will  also install the new application from new URL, but with a different name sometimes (Eg: application name -1).
      • And if it had uninstalled another application, whenever user launches this application it will prompt the uninstall screen, each time when there are more than 1 application with the same public token key.

    The Image below shows an uninstall string, which contains the application name, and public token key:

    debug

    To avoid this problem of wrong application getting uninstalled, I changed this part of the code from above code to :

    if(uninstallString.Contains(searchString)) break; 

    this:

    if(uninstallString.Contains(searchString)
                   && uninstallString.Contains("yourApp.application"))
                        break;

           

          In the code above, I’m Checking the ClickOnce application name with extension, along with the public token key to find out the correct uninstall string. that’s it!.

          Hope this solves your time in someway.

    Popularity: 9% [?]

    Continue reading...

    ClickOnce Application,Expired Certificates & Public Key Token PART I

    Thu, Jun 11, 2009

    View Comments

    Well, by this time I’m sure most of the ClickOnce application developers are aware of this problem. if you aren’t here is a basic description of what the problem is:

    Problem description

    ClickOnce allows application updates, only if the updated application manifests are signed with the same certificate (publisher) as was used to originally sign the application manifests. However, most CA’s like Verisign, and many enterprise customers own CA’s generate new certificates with new key pairs and only the same common name (CN).

    The certificate is used for the Authenticode signature element and for the strong name signature element of the manifest file to protect it against tampering, and to provide identity information for the trust manager. If the signing certificate expires and you publish an application update with a renewed certificate which has different keys, then the update will fail with the error message described in the KB article.

     

    There are lots of issues, and threads are being discussed how to resolve this issue. and these are the preferable solutions available on net.

    1. Manually Uninstall and Re install the application with new certificate – which we cannot do when we have a large number of client base who are using our ClickOnce Applicaiton.
    2. Install .net Framework 2.0 SP1 for XP /  .Net Framework 3.5 SP1 for vista or later, in these service pack s for .net Framework, this bug is fixed, and it will seamlessly update the application. – but we cannot force or inform clients to do that. yeah by this time most of the users might have installed .net framework 3.5 sp1 through windows automatic updates. but even if one guy haven’t done that KABOOM!!, clients are going to complain.
    3. Sign the new click once with 2 different keys – a solution by Daniel Margetic , even though developers may like it, when considering Automation, and  Infrastructure of build servers this might not be a favorite solution.
    4. Automatically Uninstalling the old application, and re-install the new application. – a solution by Jim Harte , using this method, we will be releasing an update for the application with expired certificate, which will have scripts for automatically uninstall the applicaiton, and install the application with new certificate, from a new location. the following thread on MSDN explains this process completely:
                VS2008 SP-1 change certificate, user can’t pick up update

      The last one seems to be a favorite of most of the people around the globe. it uses these classes by  Jim Harte  to uninstall and re install the application, using the following code:

    MessageBox.Show("Your Message to Client");
    DeploymentUtils.UninstallMe()
    DeploymentUtils.AutoInstall("<Path toNewApplication.application>");
    Application.Exit();

     

    you can have the new path as a sub folder of current applications update URL. you can get a ClickOnce applicaitons update URL using the line below :

    ApplicationDeployment.CurrentDeployment.UpdateLocation.Host

    That would do the trick. so what is it about Public Token Key ??. I will explain this in the PART 2 of this article.

    Hope it helps,

    Aneef

    I just posted the Part II of this series is here.

    Special Note:

    Thanks to RobinDotNet for his wonderful support through MSDN and through his blog to solve this problem.

    Popularity: 9% [?]

    Continue reading...

    PDB Files: What Every Developer Must Know

    Wed, May 13, 2009

    View Comments

    This is just a link post for the post below:

    PDB Files: What Every Developer Must Know

    This Morning Merill  twitted a link on his twitter, for this valuable post about PDB Files by John Robbins. honestly I didn’t know much about the importance of PDB files until I read this. 

    I  think each .Net Developer must read the post here.

    Thanks Jhon For the information, and merill for sharing this :) .

    Popularity: 6% [?]

    Continue reading...

    AirTel Sri Lanka – HSDPA a Fake Promise

    Thu, Apr 30, 2009

    View Comments

    Well I just don’t want to write a review on a network provider in a blog dedicated for .net programming, but I think its a MUST to write, so that my readers, and friends are aware of the problem with Airtel HSDPA Data Connection.

    Well here are the specs and packages for their data connection Airtel provided:

    Package Details:

    Limited: 1 GB for Rs.300 + Tax
    3 GB for Rs.600 + Tax

    Unlimited: for Rs.1499 + Tax

    Tax rates:

    VAT (Value Added Tax) = 16.67%
    MSL (Mobile Subscriber Levy) = 11.11%
    ECL (Environmental Subscriber Levy) = 2%
    Total: 29.78%

    Do they offer promised speed?

    This a question that there is no direct answer, for the unlimited package they said they offer 3.2mbps (409.6KB/s) As far as I know, people experience around 100 – 250Kb/s!

    Is there any limits like Fair User Policy?
    No, Its 100% unlimited

    I Purchased the Unlimited Package, and the much hyped First month the connectivity was ok, connecting around 320 KB/s , but from february 2009, the culprit shows its real face. the connection is as low as 13 KB/s (yeah i understand as slow as the dialup connections in old days). i called their customer care service and the only reply i got from them is this :

    “I’m very sorry for the inconvenience caused sir, but we are doing some upgrade process these days, and it will be fixed very soon”

    Poor me, believed them, and until this moment I’m writing this post, the connection wasn’t  fixed. i have called them with patience several times, and all the times I’ve got various responses from the customer care agents who had very less knowledge on the technology, which is irrelevant to the issue, and one of them were not at all caring what the customers problem was. most of the time the agents said their superior will call me back on the next morning, and non of the called me, and whatever the complaint numbers they give me is closed by them without resolution each time, whenever i call and ask about the complaint number. the above quoted text is the answer. one of them mentioned that the entire Internet is only 1MB/s and their connectivity is 3.2 MB/s . and the Internet is slow because its slower than their connectivity!?? . i hope non of you techies and geeks will agree with this (yeah can see some of you laugh ROFL) .

    One Airtel agent mentioned that their ISP’s are full and needs time to upgrade, yeah its understandable, but is that a problem for a consumer who still pays the full amount for the service? we can bare with this for a week or two, but more than a month, ARE YOU KIDDING ME? . they should have planned well and done these to handle the amount of users, now their are doing their maintenance with the cost of many users money, and time.

    Another thing i found with them is that a single connection through Internet download Manager was connecting around 13-20 KB/s , even to download a 10 MB file i had to wait more than 20 minutes, and also if i tried a concurrent download of 10 files at the same time, and each file was downloading in that speed, consuming a total bandwidth of 1MB or more. and non of the agents were able to explain me why is this happening.

    And frustrated me, sent an email about this problem to 555@airtel.lk which is their customer care email, and is said that it will be responding within few days, responded after 14 days i sent the email, with the following reply. see how responsible Airtel is about their customer problems.

    Capture

    Yeah they sent an email on 23rd of April saying that the issue will be resolved on  17th of April 2009, as per to my knowledge 17th comes before 23rd not after right?, correct me if I’m wrong guys ROFL.  and when i just called them and asked about this, guess what again the reply was the above quoted text, and a silence (poor agents I’m sure its not their faults, but they are the person we can communicate to Airtel right), and again the issue was never solved!?.

    I think if Airtel is willing to maintain the hype it made when it launched in Sri Lanka, and the Reputation of Airtel Organization, it needs to consider about waiving off the monthly charge they charged for the month cycles March, and April from their data package customers, Isn’t it unfair to charge the customer for their mistakes, and for a service which didn’t serve its promise???

    Friends in Sri Lanka, think twice before you select this Data connection, it might look like wonder when you start using it initially, but its NOT!!!!. its just an ILLUSION. I’m just posting this because i don’t want any of you guys to waste your valuable time, and money with a bad service which i experienced.

    I think i would rather upgrade my DSL line with the SLT, rather than wasting my time with Airtel Anymore. even though DSL was slower than 3.2 MB/s, it never failed its promised bandwidth!!.

    And my Final verdict:

    Airtel HSDPA Data Connection = a Fake Promise

    P.S : oh yeahh i just found that they’ve (Airtel)  removed the data connection details from their website. ;)

    Popularity: 16% [?]

    Continue reading...

    ASP.Net 3.5 ListView Control and Book Flip effect

    Thu, Apr 16, 2009

    View Comments

    one of the coolest control in ASP.Net 3.5 is its Listview Control. its too CSS friendly, and we can use it to achieve many great content presentations. if you go to scottgu’s blog you can find some good articles on how to use the listview control.

    recently I did such an implementation. its using the javascript bookflip. a great work by Will (very kind of him to share this to the world). I used the his code, and ListView to achieve a dynamic bookflip.  apart from the javascript changes,  here is the change I did for the Listview markup.

     
     
     <asp:ListView id="ImageFlip" runat="server" ItemPlaceholderID="ItemContainer">
       <LayoutTemplate>
          <div id="myBook" style="width: <%# flipWidth*2 %>px; height:
     <%# flipHeight %>px; position: relative; z-index: 5;">
            <asp:PlaceHolder ID="ItemContainer"  runat="server" />
            <div style="border: 0px solid #ddd;
        text-align: center;
        padding-top: 100px;
        margin: 0px;
        height: 0px;
        text-align:inherit;
        background-color: #ffffff;
     color: #cf0000;vertical-align:bottom" Name="Back" > 
    <img src="spongebob300/bk.jpg"  border="0" usemap="#Map" />
    </div>
    
          </div >
       </LayoutTemplate>
       <ItemTemplate>
    
       <div style="background:#ffffff ;color:#ffffff;
     cursor:url(ajax/zoom-in.cur),auto; z-index:-<%#Eval("PAGENO") %>;" 
    name="Page <%#Eval("PAGENO") %>" >
        <a href="Javascript:getFullImage(<%#Eval("ID") %>)" >
    <img src="<%#Eval("FlipImage") %>" alt="Page <%#Eval("PAGENO") %>" 
      border="0" style="cursor:url(ajax/zoom-in.cur),auto;" /></a>
        </div>
       </ItemTemplate>
       </asp:ListView>
    
     

    And the Data Retrieval is just as simple as the following 3 lines:

    DataTable dt = db.getFlipPage(catid);
    ImageFlip.DataSource = dt;
    ImageFlip.DataBind();

     

    And that’s all. very easy isn’t it. for the real implementation of this go to www.catalogues4u.com.au and click on a catalogue.In that site I have also implemented a carousel using Listview.  hope it helps.

     



    kick it on DotNetKicks.com




    Popularity: 13% [?]

    Continue reading...

    100 % CPU SQL Server 2005, Server crashes!

    Sat, Apr 11, 2009

    View Comments

    Ah back to my blog. well these days I’m on holidays for Sinhala/ Tamil New year in Sri Lanka. so anyway let met start with wishing all Sinhala  and Tamil Friends A HAPPY NEW YEAR.

    Lets get back to business, its been a long time since my last post, as usual busy schedules (i know, i know i tell this often !), but all these days i had several bits and pieces on queue for my blog, and here i am with that.

    Last week i had an early morning call from Administrators of  Catalogues4u.com.au. they said that the website is running very slow, and users are having connection timeouts in their browsers or poor performance, server logs are filled with SQLConnection Timeout. they have been receiving calls, complaints from their top management, and most of all server restarts. horrible isn’t it?  they have checked the server, and the CPU was running almost 100%, and the culprit which used the most of the CPU was SQL Server.

    After spending time in logs, and SQL profiler runs, i found that one stored procedure was taking more time to execute than the others.

    here is a part of that SP:

    SELECT  DISTINCT c.ENDDATE,c.ID, c.NAME,c.THUMBNAILURL,c.CONTENSDESCRIPTION
    INTO #temp
    FROM GW_CATELOGUE c
     INNER JOIN dbo.GW_CATELOGUE_POSTCODES cp
      ON c.ID=cp.CATELOGUEID
     INNER JOIN dbo.GW_POSTCODES p ON p.Id=cp.POSTCODEID
    WHERE  p.POSTCODE=@postcode
     AND (ENDDATE BETWEEN getDate() AND DATEADD(dd, 7, getDate()))
     AND (STARTDATE <= getDate())
     AND (ENDDATE >= getDate())
     AND c.APPROVED=1 ORDER BY c.ENDDATE

    There were some other SP’s with same structure except the  below Date Filtering which were running perfectly alright:

    AND (ENDDATE BETWEEN getDate() AND DATEADD(dd, 7, getDate()))
    AND (STARTDATE <= getDate()) AND (ENDDATE >= getDate())

    Well This made me thing something is fishy with the date. with confused mind, and help of MVP Dinesh Priyangara I Created 4 Non- Clustered Indexes on Catalogue_STARTDATE, Catalogue_ENDDATE and POSTCODE:

    CREATE INDEX Catalogue_STARTDATE ON GW_CATELOGUE(STARTDATE)
    CREATE INDEX Catalogue_ENDDATE ON GW_CATELOGUE(ENDDATE)
    CREATE INDEX PostCodes_POSTCODE ON GW_POSTCODES(POSTCODE)
    
    

    And Bang!! it worked. server  was back to normal, and everyone was happy. well this might not be a big deal, but still as somebody said, information is wealth!!.





    Popularity: 9% [?]

    Continue reading...

    Uploading Binary files or Images using LINQ to SQL

    Fri, Jan 16, 2009

    View Comments

    Today I received an email from a friend, asking how to save a binary file in to the database using LINQ to SQL.  This was the second time a person had asked me the same question, So I thought of having a blog entry about it.

    Assume that we need to upload a file  and save its name, and the file in the database table. so lets see how we do it.

    This is my Table

    CREATE TABLE [dbo].[Files2](
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [FileName] [varchar](50) NOT NULL,
        [FileSource] [image] NOT NULL,
     )
    GO
    And The Following Stored Procedure is used to Insert the Value:
     
    CREATE PROCEDURE [dbo].[ADDFILE]
    (
        @FILENAME VARCHAR(50),
        @FILESOURCE image
    )
    AS
    SET NOCOUNT ON
    
    INSERT INTO Files([FileName],[FileSource])
    VALUES(@FILENAME,@FILESOURCE)

    And the following code is used to upload and save the file using web form with a text box for file name, and a file upload control to upload the file. on the click event of a button this code is called.

    protected void Button1_Click(object sender, EventArgs e)
    {
    
         if (FileUploader.HasFile && FileUploader.PostedFile.ContentLength > 0)
          {
              string filename = txtFileName.Text;
              //Read the file in to a byte Array.
              byte[] filebyte = FileUploader.FileBytes;
    
        System.Data.Linq.Binary fileBinary = new System.Data.Linq.Binary(filebyte);
              MyDataDataContext MyData = new MyDataDataContext();
    
              MyData.ADDFILE(filename, fileBinary);
              lblStatus.Text = "File Uploaded Successfully!";
    
            }
    }
     
     

    The Main thing to remember here is that we need to pass the FileUploader.FileBytes  to the constructor of System.Data.Linq.Binary.

    To Learn more about LINQ to SQL Please visit Here.

     EDIT: Richie just showed another way to achieve this in his blog here.
     

    Popularity: 50% [?]

    Continue reading...

    Compare and update XML File with the changes

    Thu, Oct 30, 2008

    View Comments

    Recently I had a requirement to compare 2 XML Files, which has the existing and new settings of an application stored in them. what I wanted to do is when a new XML file of settings is arrived, I had to compare and retain the existing settings, and add any new ones if there are any, remove any settings if they are removed in the new one. Mainly I needed to compare nodes as well as attributes.

    Here are few suggestion I got from my friends and communities:

    1. XML Diff Patch – Couldn’t achieve what I wanted.
    2. Linq for XML -  I cannot use this as the application is developed under .net Framework 2.0

     

    So after Several Discussions and Forum Posts I Decided to Write one on my own. I don’t know whether it is the best, but it servers for my purpose. so just thought of sharing it with you all, as I saw there were a lot with the same problem. I know  it needs some improvements such as comparing nested nodes and attributes. but  this would be a better kick start. "something is better than nothing" right!!!.

     

    Here are two sample XML files which we can use for our comparison, and the output expected.

     

    Existing Settings

    <Properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <Property Name="PerformanceType1" ProID="1" Text="Gross"
     Type="ddlb" Values="On|Off">On</Property>
        <Property Name="Benchmark1" ProID="3" Text="Benchmark 1" Type="ddlb"
     Values="N/A|2nd Security Index">N/A</Property>
        <Property Name="Benchmark2" ProID="4" Text="Benchmark 2" Type="ddlb"
     Values="N/A|2nd Security Index">N/A</Property>
        <Property Name="Region1" ProID="7" Text="Column 1" Type="ddlb" 
    Values="N/A|1 Month|2 Month|3">1 Month</Property>
        <Property Name="FromDate1" ProID="8" Text="Column 1 From" 
    Type="Date">N/A</Property>
        <Property Name="FromDate9" ProID="24" Text="Column 9 From" 
    Type="Date">N/A</Property>
    </Properties>

     

    New Settings

    <Properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <Property Name="PerformanceType1" ProID="1" Text="Gross"
     Type="ddlb" Values="On|Off">On</Property>
        <Property Name="Benchmark1" ProID="3" Text="Benchmark 1" 
    Type="ddlb" Values="N/A|2nd Security Index">changed</Property>
        <Property Name="Benchmark2" ProID="4" Text="Benchmark 2" 
    Type="ddlb" Values="N/A|2nd Security Index">N/A</Property>
        <Property Name="Region1" ProID="9" Text="Changed" 
    Type="ddlb" Values="N/A|1 Month|2 Month|3">1 Month</Property>
        <Property Name="NewData" ProID="29" Text="Column 9 From" 
    Type="Date">NewlyAdded</Property>
        <Property Name="FromDate9" ProID="24" Text="Column 9 From" 
    Type="Date">N/A</Property>
    </Properties>
     
    Expected Output
     
    <Properties xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <Property Name="PerformanceType1" ProID="1" Text="Gross" 
    Type="ddlb" Values="On|Off">On</Property>
        <Property Name="Benchmark1" ProID="3" Text="Benchmark 1"
     Type="ddlb" Values="N/A|2nd Security Index">N/A</Property>
        <Property Name="Benchmark2" ProID="4" Text="Benchmark 2"
     Type="ddlb" Values="N/A|2nd Security Index">N/A</Property>
        <Property Name="Region1" ProID="9" Text="Changed"
     Type="ddlb" Values="N/A|1 Month|2 Month|3">1 Month</Property>
        <Property Name="FromDate9" ProID="24" Text="Column 9 From"
     Type="Date">N/A</Property>
        <Property Name="NewData" ProID="29" Text="Column 9 From"
     Type="Date">NewlyAdded</Property>
    </Properties>
     
     
     

    And now Lets see how the code works:

     
    string original = File.ReadAllText(@"<Original File path>");
    string New = File.ReadAllText(@"<New File path>");
    XmlCompare compare = new XmlCompare();
    XmlDocument docs=compare.compare(original, New);
    File.WriteAllText(@"<output path>", docs.OuterXml);
     
     

    The Implementation of the code and its functionality is given in the below download file, with inline comments.

    Please note few values are hard coded in this class, but can be altered to suit the requirements.

    XMLCompare.cs

    I hope it helps for a kick start!.

     

     

    Popularity: 21% [?]

    Continue reading...
    Older Entries Newer Entries
    Follow me