<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<!-- Template generated by Exclaimer Mail Disclaimers on 03:52:05 Mittwoch, 2 Juli 2014 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">P.d6e8eea9-d228-493b-a191-34b69e36b2de {
        MARGIN: 0cm 0cm 0pt
}
LI.d6e8eea9-d228-493b-a191-34b69e36b2de {
        MARGIN: 0cm 0cm 0pt
}
DIV.d6e8eea9-d228-493b-a191-34b69e36b2de {
        MARGIN: 0cm 0cm 0pt
}
TABLE.d6e8eea9-d228-493b-a191-34b69e36b2deTable {
        MARGIN: 0cm 0cm 0pt
}
DIV.Section1 {
        page: Section1
}
</style>
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<p class="d6e8eea9-d228-493b-a191-34b69e36b2de"></p>
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">I’m developing a C# application that controls VMs, starts them, stops them and runs programs in them. It should also reset the VM to a previously saved snapshot.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But I get a NullReferenceException because the Console object of my session is null, although I call LockMachine.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Here is the code with which I try to reset the machine after it has been powered down.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">public</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">void</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> Reset(</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">string</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
 snapshotName = </span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"BeforeTest"</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">        {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">Logger</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.WriteLine(</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"Resetting
 the VM"</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">var</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> writeSession =
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">new</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">SessionClass</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            m_Machine.LockMachine(writeSession,
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">LockType</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.LockType_Write);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">                <o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            </span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">int</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
 waitCycles = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">while</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> (writeSession.State
 != </span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">SessionState</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.SessionState_Locked
 & waitCycles < 100)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">               
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">Thread</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.Sleep(10);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">                waitCycles++;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">if</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> (writeSession.State
 != </span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">SessionState</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.SessionState_Locked)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">               
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">throw</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">new</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">VirtualMachineException</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">(</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"The
 VM could not be locked!"</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">var</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> console = writeSession.Console;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">if</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">(console ==
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">null</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">               
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">throw</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">new</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">VirtualMachineException</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">(</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"The
 Console is null!"</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">);
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#00B050;background:white;mso-highlight:white">//This is where the problem is found</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">var</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> snapshot = m_Machine.FindSnapshot(snapshotName);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">if</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> (snapshot ==
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">null</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">               
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">throw</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">new</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">VirtualMachineException</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">(</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"Could
 not find Snapshot \""</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> + snapshotName +
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"\""</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">var</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> progress = console.RestoreSnapshot(snapshot);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            progress.WaitForCompletion(30000);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            writeSession.UnlockMachine();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            waitCycles = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:blue;background:white;mso-highlight:white">while</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> (writeSession.State
 != </span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">SessionState</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.SessionState_Unlocked
 & waitCycles < 100)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">               
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">Thread</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.Sleep(10);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">                waitCycles++;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">            }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">           
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white;mso-highlight:white">Logger</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">.WriteLine(</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"
 The VM has been reset to the snapshot \""</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white"> + snapshotName +
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515;background:white;mso-highlight:white">"\""</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">       
</span><span style="font-size:9.5pt;font-family:Consolas;color:black;background:white;mso-highlight:white">}</span><span style="font-size:9.5pt;font-family:Consolas;color:black"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I’m using VirtualBox 4.3.12 and the COM API. How can I properly restore a snapshot? Why Is the Console null?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Best Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Daniel<o:p></o:p></span></p>
</div>
<p></p>
<p class="d6e8eea9-d228-493b-a191-34b69e36b2de"><img id="IMG1" border="0" src="cid:image772942.PNG@45783a2b.4a82e822" width="520" height="87"></p>
<p class="d6e8eea9-d228-493b-a191-34b69e36b2de"> </p>
<p><font size="1"></font></p>
</body>
</html>