{"id":103,"date":"2008-03-16T13:09:51","date_gmt":"2008-03-16T13:09:51","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=103"},"modified":"2009-04-05T07:57:34","modified_gmt":"2009-04-05T07:57:34","slug":"debugging-your-extension-code-from-visual-studio","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/debugging-your-extension-code-from-visual-studio","title":{"rendered":"Debugging your extension code from Visual Studio"},"content":{"rendered":"<p>Extension code cannot run standalone, but only within ILM. To debug the code you must first attach Visual Studio to the <strong>miiserver <\/strong>process.<\/p>\n<p><!--more--><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wapshere.com\/images\/vs-attach.gif\" alt=\"\" \/><\/p>\n<h4>Can&#8217;t see the miiserver process?<\/h4>\n<p>You may have to tick options to show all processes.<\/p>\n<h4>ILM\/MIIS installed on another machine?<\/h4>\n<p>You can attach to processes on remote servers, however you need to install the remote debug components on the ILM server (check your VS help for details).<\/p>\n<p>It is also important to ensure that the version of the dlls on the remote server matches exactly the code you are looking at in Visual Studio.<\/p>\n<h4>Insert Breakpoints<\/h4>\n<p>Once you&#8217;ve successfully attached to the process you can insert breakpoints in your code, and then start a task in Identity Manager.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.wapshere.com\/images\/vs-breakpoint.gif\" alt=\"\" width=\"587\" height=\"269\" \/><\/p>\n<p>For total VS newbies, the following are useful:<\/p>\n<ul>\n<li>F10 key to step through the code,<\/li>\n<li>F5 to continue running the code until the next breakpoint,<\/li>\n<li>Quick Watch to check the value of a variable or statement,<\/li>\n<li>Add Watch to list variables you want to keep an eye on.<\/li>\n<\/ul>\n<h4>Breakpoints not hit<\/h4>\n<p>There are a number of reasons why a breakpoint may not be hit during a debug session. Here are some suggestions:<\/p>\n<p><strong>For VS2005, symbols not loaded<\/strong><\/p>\n<p>See Brad&#8217;s answer <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en-US\/identitylifecyclemanager\/thread\/896e4676-b604-4780-b59e-005313fd5167\/\">here<\/a>.<\/p>\n<p><strong>Code not compiled with Debug option<\/strong><\/p>\n<p>Check you have compiled a &#8220;Debug&#8221; rather than a &#8220;Release&#8221; version of the dll.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wapshere.com\/images\/vs-debug-compile.gif\" alt=\"\" \/><\/p>\n<p><strong>Breakpoint in a code segment that is skipped <\/strong><\/p>\n<p>A rather obvious one this &#8211; if your breakpoint is in a subroutine, or inside something like an If or Select statement, also add a breakpoint that will be hit before the code branch, so you can find out why the segment isn&#8217;t being entered.<\/p>\n<p><strong>Breakpoint in the Initialize or Terminate subs<\/strong><\/p>\n<p>These subs are rather particular:<\/p>\n<ul>\n<li>ILM loads the Initialize sub <em>once<\/em> at the beginning of the first call to the dll;<\/li>\n<li>It keeps the Initialize sub in memory for 5 minutes <em>after<\/em> all calls the the dll finish;<\/li>\n<li>After the 5 minutes, ILM <em>runs the Terminate sub<\/em>, and unloads the Initialize sub.<\/li>\n<\/ul>\n<p>So if your breakpoint is in the Terminate sub you will have to wait 5 minutes for it to be hit!<\/p>\n<p>And if it&#8217;s in the Initialize sub, and you&#8217;re running the dll over and over again (within 5 minutes) ILM will not run it again!<\/p>\n<p>You can force ILM to reload the Initialize sub by modifying and rebuilding the dll, or by restarting the MIIS service.<\/p>\n<p><strong>MA running in a seperate process<\/strong><\/p>\n<p>In the MA configuration, if you ticked &#8220;Run this rules extension in a seperate process&#8221;, you will not be able to debug it via the miiserver process. You would have to, somehow, attach to the seperate process while it is active. It is much simpler to just make sure this option is unticked whenever you need to debug.<\/p>\n<p>Be especially aware when creating CDS extensions for Extensible MAs &#8211; they have this option ticked by default.<\/p>\n<p><strong>Provisioning (or individual dlls) turned off<\/strong><\/p>\n<p>Check that provisioning is enabled in Identity Manager under Tools -&gt; Options. Also check if this installation has XML files which switch on or off individual dlls.<\/p>\n<p><strong>Error happens before the extension code starts to run<\/strong><\/p>\n<p>Some errors (typically involving connection to the data source) happen even before the code gets a chance to run. You should see a stopped-extension-dll-exception, and there will be more information in the Windows Application Event log.<\/p>\n<h4>Preview<\/h4>\n<p>Make use of the Preview function in ILM\/MIIS to simulate a synchronization of a selected connector space object. In ILM you can now commit this preview, but for code debugging it is usually more useful to replay the sync as many times as you need to get the code right.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wapshere.com\/images\/ilm-preview.gif\" alt=\"\" \/><\/p>\n<h4>In summary<\/h4>\n<p>You can learn a lot about how ILM works by watching your code running in debug mode. It&#8217;s an essential tool for building a stable ILM environment so have fun using it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Extension code cannot run standalone, but only within ILM. To debug the code you must first attach Visual Studio to the miiserver process.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[34,28,19,30],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-ilm2007","category-miis2003","category-newbie","category-vbnet"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-1F","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":3,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/103\/revisions\/385"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}