Friday, April 3, 2009

Disable Virtual Machine Time Bomb

Deactivate virtual PC time bomb If you have whatever needs to deactivate your virtual machine time synchronization (e.g. if there are software installed in your vm expiring), you could cut and paste the following XML code snippet in vmc file:
<integration>
   <microsoft>
       <components>
           <host_time_sync>
               <enabled type="boolean">false</enabled>
           </host_time_sync>
       </components>
   </microsoft>
</integration>
Obviously, you should open vmc file with editor like notepade...
kick it on DotNetKicks.com
Save to delicious 0 saves

Monday, March 2, 2009

Update Vitual Machine Additions issue

Last week I try to attach an old virtual machine (realized in Virtual PC 2004) to my Virtual PC 2007 sp1. When I try ti update the Virtual Machine Additions to the new release I recevice the following error: "Error 1714: the older version of Virtual Machine Additions cannot be removed. Contact your support group" The same error is raised up if you try to uninstall the component from "Add or Remove Program" (Panel Control -> Add or Remove Program). So, after a long googling, I succeeded in my purpose following this steps:
  • Download Windows Installer CleanUp Utility from Microsoft site,
  • Install the utility,
  • Launch "Windows Installer CleanUp Utility" (Start -> All program -> Windows Installer CleanUp Utility),
  • "Windows Installer..." shows a list of all your programs installed on your virtual system,
  • Select item "(All user) Virtual Machine Additions [your version]" like in the figure,
  • Click "Remove",
  • Click "Ok",
  • Re-run Virtual Machine Additions program installation
Now, you are able to complete successfully the setup. Note: If you install VMA from last version of Virtual PC (VirtualPC 2007 sp1), you should have this version number: 13.820. Reference: Windows Installer CleanUp Utility
kick it on DotNetKicks.com
Save to delicious 0 saves

Monday, February 9, 2009

Declarative Workflow

Today, I began to experiment on MS WF. I find very useful the possibility to load at runtime a xaml file of my personal workflow. To reach my goal I create two project with VS 2008 to test my solution:
  • A console project which is the entry point of my application;
  • A workflow library where put my custom activity and sequence workflow.
In my workflow library I add a xaml file where I put only my custom simple sequence with only one custom activity that print a "Hello world" (see the figure below). Remember that the custom activity must be tagged as [Serializable]. My xaml file hasn't the code behind because I built my workflow in declarative manner. If you take look at xml you could see:
<SequentialWorkflowActivity x:Name="Workflow1"
     xmlns:ns0="clr-namespace:MyWorkflowLibrary.Task;
Assembly=MyWorkflowLibrary, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<ns0:HelloWorldTask x:Name="helloWorldTask1" />
</SequentialWorkflowActivity>
Note that I remove the x:Class attribute in SequentialWorkflowActivity. I do that because I haven't the compiled class in the code behind. In namespace attribute I add the reference to the assembly container of my activity, because this will be resolved at runtime. The console application "Main" looks something like this:
 static void Main(string[] args)
{
// Here, I read my xaml file containing my declarative workflow
var xmlReader =
    new XmlTextReader(
        new StringReader(
            File.ReadAllText(
                @"C:\Users\simonem\Documents\Visual Studio 2008\Projects\
                  TestWorkflow\MyWorkflowLibrary\HelloWorld.xoml")));

var runtime = new WorkflowRuntime();

runtime.StartRuntime();
runtime.WorkflowCompleted += delegate
                                 {
                                     Console.WriteLine("WorkFlow completed");
                                     Console.Read();
                                 };
try
{
    var instance = runtime.CreateWorkflow(xmlReader);
    instance.Start();

}
// Here I manage potential workflow validation exceptions
catch(WorkflowValidationFailedException wfve)
{
    var errorValidation = string.Empty;
    foreach (var error in wfve.Errors)
    {
        // StringBuilder is better...
        errorValidation += Environment.NewLine + error.ErrorText;
    }
    Console.WriteLine(errorValidation);
}
// General exceptions
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
Console.Read();

}
Troubleshooting:
  • If during the program execution you receive an error such as "Could not deserialize object. The type 'clr-namespace:MyWorkflowLibrary.Task;.HelloWorldTask' could not be resolved. startIndex cannot be larger than length of string.Parameter name: startIndex" remember to specify the assembly reference in workflow xml code (see below):
     <SequentialWorkflowActivity x:Name="Workflow1"
     xmlns:ns0="clr-namespace:MyWorkflowLibrary.Task;
Assembly=MyWorkflowLibrary, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
  • If you couldn't compile your solution and you receive the following error "Cannot compile a markup file which does not contain declaration of the new workflow type." you must change the build action on your xaml file from "Content" to "None".
References:
kick it on DotNetKicks.com
Save to delicious 0 saves