Archive

Archive for July, 2009

Static and Dynamic XAML Resources

July 22, 2009 amiraryani Leave a comment

To assign a style to a control in WPF (or Silverlight) you can use Dynamic or Static markup extension. According to MDSN Article the differences are:

The StaticResource Markup Extension processes a key by looking up the value for that key in all available resource dictionaries. This happens during loading, which is the point in time when the loading process needs to assign the property value that takes the static resource reference. The DynamicResource Markup Extension instead processes a key by creating an expression, and that expression remains unevaluated until the application is actually run, at which time the expression is evaluated and provides a value.

Categories: WPF Tags: , , ,

Dispatcher.Invoke (call an anonymous function)

July 13, 2009 amiraryani Leave a comment

In WPF to execute a code related to UI from a different thread the Dispatcher.Invoke should be used. And to avoid writing an extra delegate function you can use a anonymous function such as:

//Clear the contents of myStackPanel
this.Dispatcher.Invoke(
(Action)delegate { this.myStackPanel.Children.Clear(); }, null);

Stackoverflow.com: You need to tell the compiler what type of delegate to create ; MethodInvoker (2.0) or Action (3.5) are common choices (note they have the same signature); like so:

control.Invoke((MethodInvoker) delegate {this.Text = “Hi”;});

Another option is to write an extension method:

public static void Invoke(this Control control, Action action)
{
control.Invoke((Delegate)action);
}

then:

this.Invoke(delegate { this.Text = “hi”; });
// or simce we are using C# 3.0
this.Invoke(() => { this.Text = “hi”; });

You can of course do the same with BeginInvoke:

public static void BeginInvoke(this Control control, Action action)
{
control.BeginInvoke((Delegate)action);
}

Reference: http://stackoverflow.com/questions/253138/anonymous-method-in-invoke-call

VSTO: This action is only valid for products that are currently installed.

July 10, 2009 amiraryani Leave a comment

This is the error which I got on Windows 7  after uninstalling Visual Studio Tools for the Office system 3.0 Runtime and try to install an Office add-in. The add-in installed originally fine, but the issue raised when we uninstalled the add-in and the VSTO System 3.0 SP 1 (The service pack was installed as part installation of the Office addin):

Component Visual Studio Tools for the Office system 3.0 Runtime Service Pack 1 has failed to install with the following error message:
“This action is only valid for products that are currently installed. “

The following components failed to install:
- Visual Studio Tools for the Office system 3.0 Runtime Service Pack 1

See the setup log file located at ‘C:\Users\[USER NAME]\AppData\Local\Temp\VSD5D69.tmp\install.log’ for more information.

Solution (worked for me):
It seams that the VSTO runtime has not been uninstalled correctly and if you check the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\vsto runtime Setup\v9.0.21022 you will find that the installed value is set to 1. To fix this issue change the value to zero and try to install the add-in again. This time it should install the Visual Studio Tools for the Office system 3.0 Runtime and its Service Pack 1 correctly.

Alternative Solutions:

You can also try Windows Installer CleanUp Utility, however it did not work for me. This is also the quote from an article on consumerdocs.installshield.com about a similar issue:

Problem:

When running an installation on your computer, you may encounter error 1605 with or without the following error message:

Error 1605: “This action is only valid for products that are currently installed”.

This error is only encountered when running installations based on the Windows Installer Service.

Fix:

A: When an installation is being uninstalled from your computer
If the error occurs when the installation is being uninstalled from your computer, use Microsoft’s Windows Installer Clean Up utility to remove the installation information from the system registry. The Windows Installer Clean Up utility will not remove all the files that are installed by the installation. You will need to delete them manually. Follow these steps to accomplish this:
Download Windows Installer Clean Up utility
  1. Scroll down and click the link Download the Windows Installer Cleanup Utility package now.
  2. Save the file on your Desktop.
  3. Double-click on the downloaded file to install the Windows Installer Clean Up utility.
To remove traces of your installation from your computer:
  1. Go to Start > Programs > Windows Install Clean Up to launch the Windows Installer Clean Up.
  2. In the dialog that appears, select the installation you want to uninstall.
  3. Click Remove.
  4. Launch Windows Explorer by pressing Windows key + E or select Start > Explore.
  5. Go to the location where the installation has installed the files, usually C:\Program Files\NameofCompanyorApplication, and manually delete them. To do this, select all the files (Ctrl +A or Edit > Select All) and hit the Delete key.

B: When installing an application for the first time

Error 1605 occurs when the installation thinks that the application has already been installed once on your computer. This causes the installation to run in Maintenance mode; however, it fails in the process because a previous instance of this installation does not exist on your computer. One of the reasons why this happens is because a property called REINSTALLMODE has been set incorrectly within the installation. Follow these steps to run the installation with the correct REINSTALLMODE property.
  1. Select Start > Run.
  2. In the Open field, type
    • Windows NT 4.0, 2000. or XP: cmd.exe and click OK.
    • Windows 95 / 98 or ME: command.com and click OK.
  3. At the MS-DOS prompt, type in the path, or location, of setup.exe along with the REINSTALLMODE property, e.g., <PATH>\setup.exe /V"REINSTALLMODE="omus"

ClickOnceAddInDeploymentManager/ System.ArgumentException: Value does not fall within the expected range.

July 10, 2009 amiraryani Leave a comment

In the way of developing an Office 2007 Add-in and deploying that using click once the following error happened on a test machine after couple installing and uninstalling tests:

Name: MYAPP.Outlook2007
From: http://TestMachine/
MYAPP.Outlook2007.vsto

Value does not fall within the expected range.

************** Exception Text **************
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.DownloadAddIn(TimeSpan timeout)
at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()

The best solution which worked for us was found on MSDN forum:

….

As a last measure, if you want to get up and running again you can try to delete the ClickOnce cache after you have uninstalled the addin from the Add Remove Programs List.

On Vista, it is located at C:\Users\<user>\AppData\Local\Apps\2.0

On XP, it is located at C:\Documents and Settings\<user>\Local Settings\Apps\2.0.

Please Note: If you do decide to delete you cache you will also loose all other ClickOnce applications/add-ins that you may have installed on your machine.

After deleting the folder you should be able to re-install your add-in and it should work.


Categories: VSTO

Walkthrough: deplying Office 2007 Add-ins using ClickOnce.

July 10, 2009 amiraryani Leave a comment

The following article on MSDN is a very good walkthrough for deplying Office 2007 Add-ins using ClickOnce.

Deploying Solutions for the 2007 Office System with ClickOnce Using Visual Studio 2008 Professional: http://msdn.microsoft.com/en-us/library/bb821233.aspx

You can download a PDF copy of the article from following link:
MSDN Article

Categories: VSTO Tags: ,