<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Shri Borde's WebLog</title><link>http://blogs.msdn.com/shrib/default.aspx</link><description /><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>GitDiff.bat - power-diffing with GIT</title><link>http://blogs.msdn.com/shrib/archive/2009/04/13/gitdiff-bat-power-diffing-with-git.aspx</link><pubDate>Mon, 13 Apr 2009 16:56:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9547054</guid><dc:creator>shrib</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shrib/comments/9547054.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=9547054</wfw:commentRss><description>&lt;p&gt;As mentioned in &lt;a href="http://kernel.org/pub/software/scm/git/docs/v1.0.13/git-diff-files.html"&gt;the GIT documentation&lt;/a&gt;, you can set the environment variable GIT_EXTERNAL_DIFF to use a custom diff utility. Try doing "set GIT_EXTERNAL_DIFF=echo" and running a "git diff" command to see how GIT_EXTERNAL_DIFF works. &lt;/p&gt; &lt;p&gt;One limitation of this technique is that GIT launches the diff utility program once for every file modified. What this means is that you do not get to see the list of all files changed upfront (if you want to see how many files have changed, etc), and are also forced to review the files in the order GIT chooses. If you want to see all the test files first for example, or if you need to go back to a file you have already diffed, you have to start the "git diff" command all over again. Also, if you want to end the review half way through, you cannot do that easily and are forced to manually close the diff program multiple times until the "git diff" command terminates.&lt;/p&gt; &lt;p&gt;Luckily, there is a simple solution to this. You can use a simple script. See &lt;a href="http://github.com/shri/ironruby/blob/5e8c6b232a3c952985adbf1b9cda5c456d503cea/Merlin/Main/Languages/Ruby/Scripts/GitDiff.bat"&gt;GitDiff.bat&lt;/a&gt; (and &lt;a href="http://github.com/shri/ironruby/blob/5e8c6b232a3c952985adbf1b9cda5c456d503cea/Merlin/Main/Languages/Ruby/Scripts/GitDiff.rb"&gt;GitDiff.rb&lt;/a&gt;). The arguments to the script are the same as "git diff". However, it will show you a diff of two &lt;em&gt;folders&lt;/em&gt;, one with the old version of the files and one with the new version of the files. You can review the files in the order you chose...&lt;/p&gt; &lt;p&gt;Here is a screenshot using Beyond Compare as the diffing tool. The window at the top is the main window showing the list of files. The two windows at the bottom are diffs of two of the changed files.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/shrib/WindowsLiveWriter/GitDiff.batpowerdiffingwithGIT_1426F/GitDiff_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="1202" alt="GitDiff" src="http://blogs.msdn.com/blogfiles/shrib/WindowsLiveWriter/GitDiff.batpowerdiffingwithGIT_1426F/GitDiff_thumb.png" width="851" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Setup instructions:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Copy GitDiff.bat and GitDiff.rb to somewhere in your path  &lt;li&gt;Make sure that ruby.exe is in the path  &lt;li&gt;Go to a folder in a GIT repo  &lt;li&gt;GitDiff.bat &amp;lt;old-sha&amp;gt; &amp;lt;new-sha&amp;gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9547054" width="1" height="1"&gt;</description></item><item><title>Proposed spec for Ruby's Thread.critical=</title><link>http://blogs.msdn.com/shrib/archive/2009/01/07/proposed-spec-for-ruby-s-thread-critical.aspx</link><pubDate>Wed, 07 Jan 2009 17:24:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9288524</guid><dc:creator>shrib</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/shrib/comments/9288524.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=9288524</wfw:commentRss><description>&lt;p&gt;Ruby has &lt;a href="http://spec.ruby-doc.org/wiki/Ruby_Threading"&gt;green threads&lt;/a&gt;, and so its implementation of &lt;a href="http://www.ruby-doc.org/core/classes/Thread.html#M000461"&gt;Thread.critical=&lt;/a&gt; is speced as follows:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Sets the &lt;a href="http://www.ruby-doc.org/Thread.html#M000473"&gt;status&lt;/a&gt; of the global ``thread &lt;a href="http://www.ruby-doc.org/Thread.html#M000460"&gt;critical&lt;/a&gt;’’ condition and returns it. When set to &lt;tt&gt;true&lt;/tt&gt;, prohibits scheduling of any existing thread. Does not block &lt;a href="http://www.ruby-doc.org/Thread.html#M000449"&gt;new&lt;/a&gt; threads from being created and &lt;a href="http://www.ruby-doc.org/Thread.html#M000464"&gt;run&lt;/a&gt;. Certain thread operations (such as stopping or killing a thread, sleeping in the &lt;a href="http://www.ruby-doc.org/Thread.html#M000457"&gt;current&lt;/a&gt; thread, and raising an exception) may cause a thread to be scheduled even when in a &lt;a href="http://www.ruby-doc.org/Thread.html#M000460"&gt;critical&lt;/a&gt; section. &lt;tt&gt;Thread::critical&lt;/tt&gt; is not intended for daily use: it is primarily there to support folks writing threading libraries.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The requirement of descheduling other threads complicates things for Ruby implementations like IronRuby and JRuby which use native threads. Furthermore, most uses of Thread.critical= do not actually depend on the descheduling of other threads. This is canonical usage:&lt;/p&gt;&lt;pre style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas"&gt;&lt;p&gt;def get_unique_cookie()
&lt;p&gt;    begin
&lt;p&gt;        Thread.critical = true
&lt;p&gt;        cookie = @@counter
&lt;p&gt;        @@counter += 1
&lt;p&gt;    ensure
&lt;p&gt;        Thread.critical = false
&lt;p&gt;    end
&lt;p&gt;    cookie
&lt;p&gt;end
&lt;p&gt;&lt;/p&gt;&lt;/pre&gt;
&lt;p&gt;So most usages expect Thread.critical to behave like a critical section. Given this, here is the proposed new behavior. This behavior can be efficiently implemented even on native threads, and also works for most usage scenarios providing users with a simple locking construct.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Sets the status of the global ``thread critical’’ condition and returns it. When set to true, blocks any other thread that tries to set Thread.critical=true. It is recommend to use an ensure clause to set Thread.critical to false to exit the "global critical section".&lt;/p&gt;
&lt;p&gt;If a thread terminates while it is in the global critical section (either because of an uncaught exception, because of normal termination at the end of the block, or because of a call to Thread.kill), it leaves the process in an undefined state. Some implementations might leave the global critical section allowing other threads to enter it; some implementations might do nothing causing the app to hang if any other thread tries to set Thread.critical=true; some might exit the process.&lt;/p&gt;
&lt;p&gt;Calling "sleep" in the critical section does nothing. Calling "Thread.stop" in the global critical section also does nothing (it sets Thread.critical to false in Ruby 1.8.6).&lt;/p&gt;
&lt;p&gt;Thread.critical= is not reentrant. If a thread in the global critical section tries to set Thread.critical=true again, the behavior is undefined. Some implementations might require a single Thread.critical=false to leave the global critical section; some might require a matching number of Thread.critical=false; some might throw an exception. &lt;/p&gt;
&lt;p&gt;The behavior when calling Thread.critical=false from a thread that is not in the global critical section causes undefined behavior. Some implementations might ignore the call; some might cause the thread in the global critical section (if any) to exit the critical section; some might throw an exception.&lt;/p&gt;
&lt;p&gt;The code that executes in the global critical section should be kept to a minimum, and should ideally not call any user-defined code as it opens up the possibility of deadlocks. Since its hard to know when user-defined code can execute (because any library method may have been monkey-patched), Thread.critical= should be used very carefully. Thread::critical is not intended for daily use: it is primarily there to support folks writing threading libraries.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;We intend to propose this to ruby-core for approval.&lt;/p&gt;
&lt;p&gt;Update: Ruby 1.9 does not support Thread#critical! So this issue should go away in the future. For 1.8.*, &lt;a href="http://www.nabble.com/-ruby-core%3A20999--Supporting-Thread.critical%3Dwith-native-threads-td21224464.html"&gt;here&lt;/a&gt; is the ruby-core discussion thread. There may be a few scenarios which rely on thread descheduling, but it does seem to be marginal. JRuby is going to try to implement Thread#critical= as a global mutex. IronRuby is likely to stay on that plan too.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9288524" width="1" height="1"&gt;</description></item><item><title>OLE Automation support ON in IronPython 2.0 Beta 4</title><link>http://blogs.msdn.com/shrib/archive/2008/07/30/idispatch-support-on-in-ironpython-beta-4.aspx</link><pubDate>Wed, 30 Jul 2008 22:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8792594</guid><dc:creator>shrib</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8792594.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8792594</wfw:commentRss><description>&lt;P&gt;As I had mentioned in a &lt;A href="http://blogs.msdn.com/shrib/archive/2008/04/10/ole-automation-idispatch-support-in-ironpython.aspx" mce_href="http://blogs.msdn.com/shrib/archive/2008/04/10/ole-automation-idispatch-support-in-ironpython.aspx"&gt;previous post&lt;/A&gt;, we have added support in IronPython for accessing &lt;A href="http://en.wikipedia.org/wiki/OLE_Automation" mce_href="http://en.wikipedia.org/wiki/OLE_Automation"&gt;OLE Automation&lt;/A&gt; objects using the &lt;A href="http://msdn.microsoft.com/en-us/library/ms221608(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms221608(VS.85).aspx"&gt;IDispatch&lt;/A&gt; interface, without having to rely on interop assemblies. This was enabled with the "ipy.exe -X:PreferComDispatch" command-line until IronPython 2.0 Beta 3. In Beta 4, this behaviour is on by default. This makes IronPython's support for OLE Automation more script-friendly akin to VBScript and JScript.&lt;/P&gt;
&lt;H4&gt;See the difference&lt;/H4&gt;
&lt;P&gt;In IronPython 1.X, trying to use Excel would cause IronPython to generate the inteorp assembly on the fly, which would take more than minute, before resulting in an exception. If you explictly added a reference to Microsoft.Office.Interop.Excel.dll, then things get back on track. However, note that not all machines with Office installed will necessarily have the primary interop assemblies (&lt;A href="http://msdn.microsoft.com/en-us/library/aax7sdch.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aax7sdch.aspx"&gt;PIAs&lt;/A&gt;) installed in the GAC, as explained in &lt;A href="http://support.microsoft.com/kb/827476" mce_href="http://support.microsoft.com/kb/827476"&gt;this link&lt;/A&gt;.&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;c:\IronPython-&lt;FONT color=#00ff00&gt;1.1.2&lt;/FONT&gt;&amp;gt;ipy.exe -v&lt;BR&gt;IronPython 1.1.2 (1.1.2) on .NET 2.0.50727.1433&lt;BR&gt;Copyright (c) Microsoft Corporation. All rights reserved.&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; t = System.Type.GetTypeFromProgID("Excel.Application")&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = System.Activator.CreateInstance(t)&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add() # This will take a long time&lt;BR&gt;&lt;FONT color=#00ff00&gt;Generating Interop assembly for 000208d5-0000-0000-c000-000000000046&lt;BR&gt;&lt;/FONT&gt;Traceback (most recent call last):&lt;BR&gt;&amp;nbsp; File , line 0, in &amp;lt;stdin&amp;gt;##16&lt;BR&gt;SystemError: Could not load type 'Excel._Application' from assembly 'Excel, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null'.&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import clr&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; &lt;FONT color=#00ff00&gt;clr.AddReference("Microsoft.Office.Interop.Excel")&lt;/FONT&gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;BR&gt;
&lt;P&gt;In IronPython 2.0 &lt;A href="http://www.codeplex.com/IronPython/Release/ProjectReleases.aspx?ReleaseId=12988" mce_href="http://www.codeplex.com/IronPython/Release/ProjectReleases.aspx?ReleaseId=12988"&gt;Beta 3&lt;/A&gt;, things work much better, but as can be seen from the type of "wb", it still relies on the PIA. If the PIA is not installed or registered on the machine, IronPython would try to generate the interop assembly on the fly, again taking a very long time.&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;c:\IronPython-&lt;FONT color=#00ff00&gt;2.0B3&lt;/FONT&gt;&amp;gt;ipy.exe -v&lt;BR&gt;IronPython 2.0 Beta (2.0.0.3000) on .NET 2.0.50727.1433&lt;BR&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; t = System.Type.GetTypeFromProgID("Excel.Application")&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = System.Activator.CreateInstance(t)&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb&lt;BR&gt;&amp;lt;Microsoft.Office.Interop.Excel.WorkbookClass object at 0x000000000000002B&amp;gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb.GetType().Assembly.CodeBase&lt;BR&gt;&lt;FONT color=#00ff00&gt;'file:///C:/Windows/assembly/GAC/Microsoft.Office.Interop.Excel/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll'&lt;BR&gt;&lt;/FONT&gt;&amp;gt;&amp;gt;&amp;gt; excel.Quit()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;
&lt;P&gt;In IronPython 2.0 Beta 4, things just work, thanks to the shiny new OleAut support. "wb" is just a simple COM object that supports IDispatch, and there is no need for a PIA anymore!&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;c:\IronPython-&lt;FONT color=#00ff00&gt;2.0B4&lt;/FONT&gt;&amp;gt;ipy.exe -v&lt;BR&gt;IronPython 2.0 Beta (2.0.0.4000) on .NET 2.0.50727.1433&lt;BR&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; t = System.Type.GetTypeFromProgID("Excel.Application")&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = System.Activator.CreateInstance(t)&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb&lt;BR&gt;&lt;FONT color=#00ff00&gt;&amp;lt;System.__ComObject (_Workbook) object at 0x000000000000002B&amp;gt;&lt;BR&gt;&lt;/FONT&gt;&amp;gt;&amp;gt;&amp;gt; excel.Quit()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Different ways to get started&lt;/H4&gt;
&lt;P&gt;IDispatch is about invoking a method on an existing OleAut object. But how do you get to an OleAut object in the first place? VBScript and VBA have a method called CreateObject to create an OleAut object. There are multiple ways of doing the same in IronPython. &lt;/P&gt;
&lt;P&gt;The first is to use the &lt;A href="http://msdn.microsoft.com/en-us/library/system.type.gettypefromprogid(VS.71).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.type.gettypefromprogid(VS.71).aspx"&gt;Type.GetTypeFromProgID&lt;/A&gt; method as shown here. This is the simplest solution.&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; &lt;FONT color=#00ff00&gt;t = System.Type.GetTypeFromProgID("Excel.Application")&lt;/FONT&gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = System.Activator.CreateInstance(t)&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;The second way is to use the new "clr.AddReferenceToTypeLibrary"&amp;nbsp; function. This currently requires hard-coding the &lt;A href="http://msdn.microsoft.com/en-us/library/aa372092.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa372092.aspx"&gt;GUID of the typelib&lt;/A&gt; (we could consider easier ways in the future). However, the advantage is that you can access the typelib just like a Python module. This is particularly handy if you need to access enum values in your program. Using the TLB, you can use the symbolc enum names instead of hard-coding int constants.&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excelTypeLibGuid = System.Guid("00020813-0000-0000-C000-000000000046")&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import clr&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; &lt;FONT color=#00ff00&gt;clr.AddReferenceToTypeLibrary(excelTypeLibGuid)&lt;/FONT&gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; from Excel import Application&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = Application()
&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, you can use the PIA as before. There is no particular advantage to doing this. It just means that your old code will keep on working as before (though method invocation will use the new IDispatch mechanism).&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;&amp;gt;&amp;gt;&amp;gt; import clr&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; &lt;FONT color=#00ff00&gt;clr.AddReference("Microsoft.Office.Interop.Excel")&lt;/FONT&gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; from Microsoft.Office.Interop.Excel import Application&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = Excel()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;All of the above techniques end up calling the Win32 function &lt;A href="http://msdn.microsoft.com/en-us/library/ms686615.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms686615.aspx"&gt;CoCreateInstance&lt;/A&gt;. So one more technique you could use is to make a pinvoke call to CoCreateInstance!&lt;/P&gt;
&lt;P&gt;Once you have created a COM object, the rest of the code to access the object should work pretty much like before; it just wont require the presence of a PIA.&lt;/P&gt;
&lt;H4&gt;How to turn back the clock?&lt;/H4&gt;
&lt;P&gt;If you run into any bugs with the new OleAut support, there is a way to get to the old behavior. This is done by setting an environment variable called COREDLR_PreferComInteropAssembly to "TRUE" as show here. Do report the bug to &lt;A href="mailto:users@lists.ironpython.com" mce_href="mailto:users@lists.ironpython.com"&gt;users@lists.ironpython.com&lt;/A&gt; so that the issue can be fixed. COREDLR_PreferComInteropAssembly might go away in the future.&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;c:\IronPython-2.0B4&amp;gt;ipy.exe&lt;BR&gt;IronPython 2.0 Beta (2.0.0.4000) on .NET 2.0.50727.1433&lt;BR&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; t = System.Type.GetTypeFromProgID("Excel.Application")&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = System.Activator.CreateInstance(t)&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb&lt;BR&gt;&lt;FONT color=#00ff00&gt;&amp;lt;System.__ComObject (_Workbook) object at 0x000000000000002B&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; ^Z 
&lt;BR&gt; &lt;BR&gt;c:\IronPython-2.0B4&amp;gt;&lt;FONT color=#00ff00&gt;set COREDLR_PreferComInteropAssembly=TRUE&lt;/FONT&gt; 
&lt;BR&gt; &lt;BR&gt;c:\IronPython-2.0B4&amp;gt;ipy.exe&lt;BR&gt;IronPython 2.0 Beta (2.0.0.4000) on .NET 2.0.50727.1433&lt;BR&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; t = System.Type.GetTypeFromProgID("Excel.Application")&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; excel = System.Activator.CreateInstance(t)&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb = excel.Workbooks.Add()&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb&lt;BR&gt;&amp;lt;Microsoft.Office.Interop.Excel.WorkbookClass (Workbook) object at 0x000000000000002B&amp;gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; wb.GetType()&lt;BR&gt;&lt;FONT color=#00ff00&gt;&amp;lt;System.RuntimeType object at 0x000000000000002C [Microsoft.Office.Interop.Excel.WorkbookClass]&amp;gt;&lt;/FONT&gt;&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt;&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/PRE&gt;
&lt;H4&gt;Known issues&lt;/H4&gt;
&lt;P&gt;There are few expected differences to be aware of.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;There is one important detail worth pointing out. IronPython tries to use the typelib of the OleAut object if it can be found, in order to do name resolution while accessing methods or properties. The reason for this is that the IDispatch interface does not make much of a distinction between properties and method calls. This is because of VB6 semantics where "excel.Quit" and "excel.Quit()" have the exact same semantics. However, IronPython has a strong distinction between properties and methods, and methods are first class objects. For IronPython to know whether "excel.Quit" should invoke the method Quit, or just return a callable object, it needs to inspect the typelib. If a typelib is not available, IronPython assumes that it is a method. So if a OleAut object has a property called "prop" but it has no typelib, you would need to write "p = obj.prop()" in IronPython to read the property value. This behavior is by design.&lt;/LI&gt;
&lt;LI&gt;Calling a method with "out" (or in-out) parameters requires explicitly passing in an instance of "clr.Reference" as described in &lt;A href="http://blogs.msdn.com/haibo_luo/archive/2007/10/04/5284947.aspx" mce_href="http://blogs.msdn.com/haibo_luo/archive/2007/10/04/5284947.aspx"&gt;this blog&lt;/A&gt;, if you want to get the updated value from the method call. Note that COM methods with out parameters are not considered Automation-friendly. JScript does not support out parameters at all. If you do run into a COM component which has out parameters, having to use "clr.Reference" is a reasonable workaround. Another workaround is to leverage the inteorp assembly by using the full method name syntax of "outParamAsReturnValue = InteropAssemblyNamespace.IComInterface(comObject)".&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Note that the Office APIs do have "VARIANT*" parameters, but there methods do not update the value of the VARIANT. The only reason they were defined with "VARIANT*" parameters was for performance since passing a pointer to a VARIANT is faster than pushing all the 4 DWORDs of the VARIANT onto the stack. So you can just treat such parameters as "in" parameters.&lt;/LI&gt;
&lt;LI&gt;Real world examples of APIs with out parameters are &lt;A class="" href="http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx"&gt;ADODB.Command.Execute&lt;/A&gt;, most of the &lt;A class="" href="http://msdn.microsoft.com/en-us/library/ms697837(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms697837(VS.85).aspx"&gt;Microsoft Agent APIs&lt;/A&gt;. If you run into any others, let me know, so that I can compile a list here for reference. If this issue affects many scenarios, we could consider returning the out parameters as a return value tuple. This would require checking the ITypeInfo to check the type of parameters. We have avoided doing this so that we can have the same consistent code path irrespective of whether the typelib is available or not.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P&gt;Currently, there are a few bugs in corner cases:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Passing a Python long (BigInteger) as an argument to a COM method expecting a LONGLONG causes a TypeError (InvalidCastException).&lt;/LI&gt;
&lt;LI&gt;Passing some types of objects (eg "xrange(1)") to a COM method expecting an IUnknown results in a TypeError (InvalidCastException).&lt;/LI&gt;
&lt;LI&gt;There are some corner cases where code that would have throw an exception before is now allowed. For example, it is possible to pass any object to a COM method expecting a BSTR. This is because the&amp;nbsp; default IDispatch marshalling rules allow this. Noone should be affected by this because it is a negative scenario anyway.&lt;/LI&gt;&lt;/UL&gt;
&lt;H4&gt;Under the hoods&lt;/H4&gt;
&lt;P&gt;Running with "ipy.exe -X:ShowRules", you can see that the generated code makes pinvoke calls on the IDispatch interfaces. This is similar to what VBScript (or VBA late bound code) would have done. UnsafeMethods.IDisaptchInvoke is a helper function in Microsoft.Scripting.Core.dll that will dereference the vtable of the OleAut object, get the function pointer for IDispatch::Invoke, and make a call to the function pointer.&lt;/P&gt;&lt;PRE style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: consolas"&gt;&amp;gt;&amp;gt;&amp;gt; wb = com.Workbooks&lt;BR&gt;//&lt;BR&gt;// AST: Rule&lt;BR&gt;// .scope &amp;lt;rule&amp;gt; (&lt;BR&gt;) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .if ((((.arg $arg0) != .null) &amp;amp;&amp;amp; (Marshal.IsComObject)(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.arg $arg0),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )) ) {.return .site (Object) GetMember Workbooks( // Python GetMember Workbooks IsNoThrow: False&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ComObject.ObjectToComObject)(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.arg $arg0),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.arg $arg1)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } .else {/*empty*/;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }}
&lt;BR&gt;// AST: Rule&lt;BR&gt;// 
&lt;P&gt;.scope &amp;lt;rule&amp;gt; (&lt;BR&gt;) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .if (((((.arg $arg0) != .null) &amp;amp;&amp;amp; (((Object)(.arg $arg0)).(Object.GetType)() == ((Type)IDispatchComObject))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) &amp;amp;&amp;amp; ((IDispatchComObject)(.arg $arg0).ComTypeDesc == (ComTypeDesc)System.Scripting.Com.ComTypeDesc)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) ) {.scope (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Scripting.Com.IDispatchObject dispatchObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.IntPtr dispatchPointer&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32 dispId&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Runtime.InteropServices.ComTypes.DISPPARAMS dispParams&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Scripting.Com.Variant invokeResult&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Object returnValue&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .scope (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#00ff00&gt;(.var dispId) = (ComMethodDesc)Object&amp;amp;&amp;nbsp; Workbooks().DispId&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispParams).cArgs = 0&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispParams).cNamedArgs = 0&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispatchObject) = (IDispatchComObject)(.arg $arg0).DispatchObject&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispatchPointer) = ((.var dispatchObject)).(IDispatchObject.GetDispatchPointerInCurrentApartment)(&lt;BR&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .try {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .scope (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Scripting.Com.ExcepInfo excepInfo&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.UInt32 argErr&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32 hresult&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var hresult) = (&lt;FONT color=#00ff00&gt;UnsafeMethods.IDispatchInvoke&lt;/FONT&gt;)(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispatchPointer),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispId),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (INVOKEKIND)INVOKE_FUNC, INVOKE_PROPERTYGET,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispParams),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var invokeResult),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var excepInfo),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var argErr),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ComRuntimeHelpers.CheckThrowException)(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var hresult),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var excepInfo),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var argErr),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Workbooks",&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var returnValue) = ((.var invokeResult)).(Variant.ToObject)()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } .finally {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((.var dispatchObject)).(IDispatchObject.ReleaseDispatchPointer)(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.var dispatchPointer),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((.var invokeResult)).(Variant.Clear)()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .return (.var returnValue);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } .else {/*empty*/;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }}&lt;/P&gt;&lt;/PRE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8792594" width="1" height="1"&gt;</description></item><item><title>CLS compilation of IronPython</title><link>http://blogs.msdn.com/shrib/archive/2008/07/24/cls-compilation-of-ironpython.aspx</link><pubDate>Thu, 24 Jul 2008 05:01:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8768752</guid><dc:creator>shrib</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8768752.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8768752</wfw:commentRss><description>&lt;p&gt;One of the common feature requests for IronPython is to support static compilation. While the feature looks like a no-brainer initially, it does have a few wrinkles when you look at the details. Here are the different forms that a related question might look like?&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Can I call IronPython code from C#?&lt;/li&gt; &lt;li&gt;Can I statically compile my IronPython source code to a binary?&lt;/li&gt; &lt;li&gt;Can I define &lt;a href="http://msdn.microsoft.com/en-us/library/system.attribute.aspx"&gt;custom attributes&lt;/a&gt; in IronPython?&lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;Terminology&lt;/h4&gt; &lt;p&gt;This has several aspects related to compilation, with different folks caring about different aspects of the issue. To clarify the issues involved, here is the terminology I will use.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Compiling to an assembly on disk - This is useful if you do not want to ship your source code. This by itself does not imply if the IL it contains is CLS compliant or not. IronPython 1.X does support this feature, and IronPython 2 will be restoring the feature in Beta 4 (due shortly).&lt;/li&gt; &lt;li&gt;Generating CLS compliant IL - &lt;a href="http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx"&gt;Common Language Specification&lt;/a&gt; (CLS) specifies the requirements on IL (and metadata) so that it can be seamlessly consumed from other statically compiled languages like C# and VB.Net.&amp;nbsp; IronPython normally generates mangled IL to implement all the dynamic features of Python which cannot be represented with CLS compliant IL in general. However, users are willing to put up with some restrictions in order to get CLS compliant code (which can be either on disk or in-memory).&lt;/li&gt; &lt;li&gt;Calling IronPython code from C# - Many folks assumes this implies compilation of IronPython code, but this is not true. See the Alternatives section below.&lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;CLS compilation usage scenarios&lt;/h4&gt; &lt;p&gt;This blog is about the CLS compliant compilation aspect. While CLS compliance is a nice goal by itself, it is interesting to think of the different ways that the generated IL could be consumed.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Authoring .NET assemblies - The compiled assembly would be referenced from statically typed language like C# or VB.Net. This would be consumed using something like "csc /r:PythonWidgetAssembly.dll app.cs". The author of PythonWidgetAssembly.dll would probably want IronPython to support the full range of CLS features as she wants to use IronPython as a first-class languages completely on par with C# and VB.Net.&lt;/li&gt; &lt;li&gt;Reflection on the generated assembly - This is used by tools like NUnit which look for all types in a test assembly with a given custom attribute. Similarly, a host might look in a plugin assembly for a type inherting from some known interface.&lt;/li&gt; &lt;li&gt;Reflection on an object at runtime - Some .NET API might inspect its incoming argument object for a method with given name, or a property with a custom attribute. &lt;a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx"&gt;LINQ to SQL&lt;/a&gt; looks for custom attributes like &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.tableattribute.aspx"&gt;TableAttribute&lt;/a&gt; on the class of the object being used in a LINQ query to determine how to map the LINQ query to a database operation. Normally, IL generanted by Python is mangled so that a Python class method does not really exist on instances of the Python class. Also, Python does not have a concept of custom attributes.&lt;/li&gt;&lt;/ol&gt; &lt;h4&gt;Issues&lt;/h4&gt; &lt;ul&gt; &lt;li&gt;First two usage patterns, you need to explicitly compile your Python code to an assembly. This takes away one of the important qualities of Python which is the ability to just run your source code (as "ipy.exe foo.py") without an extra compile step. In general, you want the code to have the same semantics irrespective of whether you precompile it to as assembly on disk, or not.&lt;/li&gt; &lt;li&gt;Extensions to Python syntax - Expressing the full range of CLS features will need adding new syntax to IronPython. For example, Python has no syntax for accessibility of members (public, protected, private, internal, etc), method type like virtual or abstract, the type of arguments or the return type, custom attributes on assembly, types, methods, and arguments, specifying events, etc. See the description of &lt;a href="http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx"&gt;CLS&lt;/a&gt; for the complete list. It could stay valid Python code by expressing the features as comments or interpreting existing Python elements in creative ways. But at some point, it will start becoming P# in appearance (ie. not quite Python). At that point, would you be better off writing those parts of your application in C# or VB.Net?&lt;/li&gt; &lt;li&gt;Extensions to Python semantics - All Python name resolution is dynamic. For eg, if you had "System.Console.WriteLine("foo")", then the name "System" is usually resolved at runtime. For the first two usage patterns, IronPython would need to attempt to bind this at compile-time which does bend the rules. In general, IronPython's support of .NET is done in a very Pythonic way. IronPython code using .NET code can in theory also run under CPython if the .NET libraries were implemented as Python libraries. There is an experimental project called &lt;a href="http://code.google.com/p/python-system/"&gt;Python-System&lt;/a&gt; which attempts to do this. This would be a tall task, but the point is that IronPython has not bent the core semantics of the language.&lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;Alternatives&lt;/h4&gt; &lt;p&gt;I do want to provide people with some possible alternative solutions that might work for their scenarios in the meantime&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Writing part of the application in C# or VB.Net, and then extending it from IronPython - For example, you could define the SQL-related types in C# or VB.Net so that you could set the custom attributes from the System.Data.Linq namespace. (This would not work as IronPython does not support authoring LINQ queries yet, but it illustrates the point)&lt;/li&gt; &lt;li&gt;Using the &lt;a href="http://compilerlab.members.winisp.net/dlr-spec-hosting.doc"&gt;DLR hosting APIs&lt;/a&gt; to call into IronPython code from C# or VB.Net&lt;/li&gt; &lt;li&gt;In the future, languages could possibly provide better support to call into IronPython as discussed in &lt;a href="http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx"&gt;this blog&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;Conclusion&lt;/h4&gt; &lt;p&gt;Usage 3 above (Reflection on an object at runtime) seems like the main issue to me as the user is not trying to persist an assembly to disk (which is not Pythonic). &lt;/p&gt; &lt;p&gt;Also, some features might provide big bang for the buck (like custom attributes on types and members as required by LINQ to SQL), whereas supporting the full range of CLS features may not be warranted. I would be curious to hear of real world use-case of how people want to use "static compilation" to understand what the right design point is. &lt;/p&gt; &lt;p&gt;If you have run into a wall with trying to use IronPython because of one of the issues above, do leave a comment about your exact scenario, which libraries were involved, what your workaround was, etc.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8768752" width="1" height="1"&gt;</description></item><item><title>Signals on Windows</title><link>http://blogs.msdn.com/shrib/archive/2008/05/23/signals-on-windows.aspx</link><pubDate>Fri, 23 May 2008 23:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8542313</guid><dc:creator>shrib</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8542313.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8542313</wfw:commentRss><description>&lt;P&gt;While looking at signal support in IronRuby, I played with the &lt;A href="http://msdn.microsoft.com/en-us/library/xdkz3x12(VS.71).aspx" mce_href="http://msdn.microsoft.com/en-us/library/xdkz3x12(VS.71).aspx"&gt;signal&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/dwwzkt4c(VS.71).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dwwzkt4c(VS.71).aspx"&gt;raise&lt;/A&gt; functions that are available in the C runtime. It turns out that these functions are much more limited than their Unix counterparts. On Unix, &lt;A href="http://en.wikipedia.org/wiki/Kill_%28Unix%29" mce_href="http://en.wikipedia.org/wiki/Kill_%28Unix%29"&gt;kill&lt;/A&gt; can be used to send a signal to another process, enabling cross-process communication.&lt;/P&gt;
&lt;P&gt;However, the CRT raise function does not take a process id. It can only send a synchronous signal on the same thread to the process it is being called from. This does not seem to be of much use. SIGINT (Ctrl-C) can also be dealt with using &lt;A href="http://msdn.microsoft.com/en-us/library/ms686016.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms686016.aspx"&gt;SetConsoleCtrlHandler&lt;/A&gt; in unmanaged code, or &lt;A href="http://msdn.microsoft.com/en-us/library/system.console.cancelkeypress.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.console.cancelkeypress.aspx"&gt;Console.CancelKeyPress&lt;/A&gt; in managed code, and the Windows runs the handler on a separate thread. SIGILL, SIGSEGV, and SIGTERM are not generated on Windows NT. So that only leaves SIGABRT and SIGFPE. Not sure how important these are.&lt;/P&gt;
&lt;P&gt;If asynchronous signals were truly supported on existing threads, this would present challenges to using managed code to handle the signals. The thread may not be in an interruptible state when the handler is run. If the handler triggers a GC or stack-walk, that would cause trouble. Also, running managed code can allocate memory since the code may not have been JITed. Doing such heavy-weight operations in the handler would also lead to trouble. &lt;A class="" href="http://www.python.org/doc/2.4/lib/module-signal.html" mce_href="http://www.python.org/doc/2.4/lib/module-signal.html"&gt;Python&lt;/A&gt; ("they can only occur between the ``atomic'' instructions of the Python interpreter") and &lt;A class="" href="http://perldoc.perl.org/perlipc.html#Deferred-Signals-(Safe-Signals)" mce_href="http://perldoc.perl.org/perlipc.html#Deferred-Signals-(Safe-Signals)"&gt;Perl&lt;/A&gt; ("to avoid these problems signals are deferred") seem to defer running of the signal handler from a safe point, or run it on a &lt;A class="" href="http://www.xav.com/perl/lib/Thread/Signal.html" mce_href="http://www.xav.com/perl/lib/Thread/Signal.html"&gt;new thread &lt;/A&gt;like SIGINT on Windows.&lt;/P&gt;
&lt;P&gt;I am attaching a test case to use signals from managed code if anyone wants to play with it. All handlers are run synchronously. Ctrl-C is run asynchronously but on a new thread.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8542313" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/shrib/attachment/8542313.ashx" length="2287" type="text/plain" /></item><item><title>Accessing IronPython objects from native JScript (using IReflect)</title><link>http://blogs.msdn.com/shrib/archive/2008/05/13/accessing-ironpython-objects-from-native-jscript-using-ireflect.aspx</link><pubDate>Tue, 13 May 2008 21:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8501816</guid><dc:creator>shrib</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8501816.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8501816</wfw:commentRss><description>&lt;P&gt;The DLR aims to enable dynamic languages like &lt;A href="http://www.codeplex.com/IronPython" mce_href="http://www.codeplex.com/IronPython"&gt;IronPython&lt;/A&gt; and &lt;A href="http://ironruby.rubyforge.org/" mce_href="http://ironruby.rubyforge.org/"&gt;IronRuby&lt;/A&gt; to access and minipulate objects created by each other. But what about dynamic languages like JScript implemented using unmanaged code? It is sometimes useful for IronPython and native JScript to interact with each other. Consider the following scenarios:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;IronPython could be used to host a &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx"&gt;System.Windows.Forms.WebBrowser&lt;/A&gt; control which loads a Web page with native JScript. See &lt;A href="http://msdn.microsoft.com/en-us/library/a0746166.aspx" mce_href="http://msdn.microsoft.com/en-us/library/a0746166.aspx"&gt;this MSDN article&lt;/A&gt; for a description of the WebBrowser control. Srivatsn discusses some of the issues related to using it from IronPython &lt;A href="http://blogs.msdn.com/srivatsn/archive/2008/05/09/accessing-ironpython-objects-from-native-javascript.aspx" mce_href="http://blogs.msdn.com/srivatsn/archive/2008/05/09/accessing-ironpython-objects-from-native-javascript.aspx"&gt;here&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;Native Web browser JScript could talk with &lt;A href="http://silverlight.net/learn/dynamiclanguages.aspx/" mce_href="http://silverlight.net/learn/dynamiclanguages.aspx/"&gt;IronPython running in a Silverlight 2 application&lt;/A&gt; embedded in the Web page. (Note that unfortunately, this scenario will not currently work. See "Issues and Limitations" #1 below.)&lt;/LI&gt;
&lt;LI&gt;VBA macros running inside Office could load and run IronPython scripts.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;IronPython is now able to access native JScript objects because of the &lt;A href="http://blogs.msdn.com/shrib/archive/2008/04/10/ole-automation-idispatch-support-in-ironpython.aspx" mce_href="http://blogs.msdn.com/shrib/archive/2008/04/10/ole-automation-idispatch-support-in-ironpython.aspx"&gt;IDispatch support&lt;/A&gt; we have added to the DLR.&lt;/P&gt;
&lt;P&gt;For the reverse direction of native JScript accessing IronPython objects, the IronPython objects need to be marshalled to unmanaged code as &lt;A href="http://msdn2.microsoft.com/en-us/library/ms221608.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms221608.aspx"&gt;IDispatch&lt;/A&gt; (and ideally also &lt;A href="http://msdn.microsoft.com/en-us/library/sky96ah7(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/sky96ah7(VS.85).aspx"&gt;IDispatchEx&lt;/A&gt;). I had &lt;A href="http://blogs.msdn.com/shrib/archive/2007/09/04/ireflect-and-idispatch.aspx" mce_href="http://blogs.msdn.com/shrib/archive/2007/09/04/ireflect-and-idispatch.aspx"&gt;previously discussed&lt;/A&gt; how managed types can implement &lt;A href="http://msdn2.microsoft.com/en-us/library/system.reflection.ireflect.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.reflection.ireflect.aspx"&gt;System.Reflection.IReflect&lt;/A&gt; to be marshalled as IDispatch. Reading Srivatsn's blog, I decided to see how I could build on this IReflect &amp;lt;-&amp;gt; IDispatch mapping. This turns out to be fairly straightforward. I have implemented a Python modules called IReflectUtils. This allows an IronPython class to trivally indicate that it wants to make itself accessible to native JScript. The IronPython class declaration looks like the following:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;from IReflectUtils import IReflectBase &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;class TestClass(IReflectBase):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def foo(self):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "In TestClass.foo"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;All it takes is inheriting from a single class IReflectBase. No other change is needed. At that point, the Python class becomes accessible from native JScript. JScript can invoke any of the methods of the Python class, including dynamically added methods. JScript can also read and write any of the attributes defined on the object. Tada!&lt;/P&gt;
&lt;P&gt;Note that because of a bug in IronPython, IReflectBase needs to be the first base type specified. So the class declaration in &lt;A href="http://blogs.msdn.com/srivatsn/archive/2008/05/09/accessing-ironpython-objects-from-native-javascript.aspx" mce_href="http://blogs.msdn.com/srivatsn/archive/2008/05/09/accessing-ironpython-objects-from-native-javascript.aspx"&gt;Srivatsn's blog&lt;/A&gt; would become:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;class MyForm(IReflectBase, Form):&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;H4&gt;How it works&lt;/H4&gt;
&lt;P&gt;Under the hoods, IReflectBase implements IReflect. It needs to implement the following two main functions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.getmethods.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.getmethods.aspx"&gt;IReflect.GetMethods&lt;/A&gt; - this is implemented by calling "dir" on the object and returning all the attributes as method names. The function needs to return the method names as an array of MethodInfo, and so we have to create a subtype of MethodInfo which basically just knows the name it corresponds to.&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.getmethods.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.getmethods.aspx"&gt;IReflect.InvokeMember&lt;/A&gt; - this turns into a "getattr(target, name)", possibly followed by a call to the returned object. The invokeAttr parameter that is passed into the method indicates whether the Python attribute should just be returned (if &lt;A href="http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx"&gt;BindingFlags&lt;/A&gt;.GetProperty is set), or if it should be invoked (if BindingFlags.InvokeMethod is set)&lt;/LI&gt;&lt;/UL&gt;
&lt;H4&gt;Issues and limitations&lt;/H4&gt;
&lt;OL&gt;
&lt;LI&gt;This solution will not work on Silverlight 2 which currently does not include any COM Support. Hence, it does not support the IReflect &amp;lt;-&amp;gt; IDispatch mapping. It would be possible to port this functionality from .NET Frameworks to a future version of Silverlight.&lt;/LI&gt;
&lt;LI&gt;This solution will only work with IE, since only Microsoft's JScript implementation is based on IDispatch. Firefox's implementation uses a similar but different interface that is part of XPCOM. I do not what the XPCOM interface looks like, but if it is similar to IDispatch, it should be possible to map IReflect to it as well.&lt;/LI&gt;
&lt;LI&gt;Python classes with __getattribute__ will not work. The CLR calls IReflect.GetMethodNames to get a full list of methods supported by the object. This is different than IDispatch.GetIDsOfNames which only supports querying whether a single given method is supported or not (which is similar to how __getattribute__ works). Because of this, such Python classes will not be able to expose all the method names that __getattribute__ recognizes. IReflect does have a &lt;A href="http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.getmethod.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.getmethod.aspx"&gt;GetMethod&lt;/A&gt; method that could have been used to query whether a specific method existed, but the IReflect &amp;lt;-&amp;gt; IDispatch mapping does not use this. A theoretical solution is for IReflect.GetMethodNames to return the complete infinite set of all character combinations, but this does not really work. Ruby's method_missing will run into the same issue. This will need a creative fix to the IReflect &amp;lt;-&amp;gt; IDispatch mapping, or for a new interface to be added to the CLR which more closely follows the IDispatch model.&lt;/LI&gt;
&lt;LI&gt;This feature could be shipped in different ways. The attached sample show a simple Python module. This could even be used with &lt;A href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=v1.1.1%20Release%20Notes&amp;amp;referringTitle=Home" mce_href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=v1.1.1%20Release%20Notes&amp;amp;referringTitle=Home"&gt;IronPython 1.X&lt;/A&gt;. However, it requires that all Python classes explicitly opt in, which may not work well for large existing code bases. Also, builtin types with dynamic behavior implemented by IronPython.dll will not work as the user cannot make them implement IReflect. The feature could be built into the IronPython runtime so that all IronPython user-defined classes would implicitly inherit from IReflect, and any builtin types could be made to implement IReflect.&lt;/LI&gt;
&lt;LI&gt;The current solution relies on inheriting from IReflect (via IReflectBase). This can lead to name collisions if the user defines method with names which are the same as some significant IReflect method.&lt;/LI&gt;
&lt;LI&gt;VBScript does not require the use of paranthesis while calling a method with no arguments. This makes ambiguous the syntax for an instance method call and a property access. This can cause some issues since the IReflect.InvokeMember needs to know whether a property should be accessed or if the attribute should be invoked. Similarly, VBScript and IDispatch are case-insensitive whereas Python is case-sensitive. The IReflect &amp;lt;-&amp;gt; IDispatch mapping seems to do a case-insensitive search and randomly picking an attribute if there are multiple matches.&lt;/LI&gt;
&lt;LI&gt;We could support richer interaction between managed and unmanaged dynamic languages by taking advantage of the &lt;A href="http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.expando.iexpando.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.expando.iexpando.aspx"&gt;System.Runtime.InteropServices.Expando.IExpando&lt;/A&gt; &amp;lt;-&amp;gt; IDispatchEx mapping that the CLR supports. This would allow addition and deletion of attributes. This is currently left as an exercise for the user. Also, note that this feature has bugs in it, and the support may not be sufficient for all the scenarios you would care about.&lt;/LI&gt;&lt;/OL&gt;
&lt;H4&gt;About the attached file&lt;/H4&gt;
&lt;P&gt;IReflectUtils.zip contains the following files:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;IReflectUtils.py - The main Python module file. This file can be used in your own IronPython projects.&lt;/LI&gt;
&lt;LI&gt;TestClass.py - A sample Python class that inherits from IReflectUtils.py&lt;/LI&gt;
&lt;LI&gt;ManagedFactory.cs - A bridge between test.js/test.vbs and TestClass.py. It includes a class that is ComVisible and hence can be instantiated by test.js and test.vbs. The class loads TestClass.py and passes the IronPython object back to test.js and test.vbs. See the top of the file for instructions on compiling and registering the file.&lt;/LI&gt;
&lt;LI&gt;test.js and test.vbs - The driver files which instantiate ManagedFactory, use it to get an IronPython object, and then access the object. See the top of the file for instructions on running the files.&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8501816" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/shrib/attachment/8501816.ashx" length="2992" type="application/x-zip-compressed" /></item><item><title>OLE automation (IDispatch) support in IronPython</title><link>http://blogs.msdn.com/shrib/archive/2008/04/10/ole-automation-idispatch-support-in-ironpython.aspx</link><pubDate>Thu, 10 Apr 2008 21:57:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8376797</guid><dc:creator>shrib</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8376797.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8376797</wfw:commentRss><description>&lt;h3&gt;IronPython 1.X&lt;/h3&gt; &lt;p&gt;IronPython 1.X supported COM interop by building on top of the &lt;a href="http://msdn2.microsoft.com/en-us/library/6bw51z5z(VS.80).aspx"&gt;COM interop&lt;/a&gt; support built into the CLR. This relies on the use of interop assemblies for managed code to access COM objects. The interop assembly can be accessed in different ways:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;clr.AddReference("interopAssembly") - This is the preferred mechanism so that the interop assembly does not have to be created multiple times. The down-side is that it complicates deployment. You have to &lt;a href="http://msdn2.microsoft.com/en-us/library/697w37zd(VS.80).aspx"&gt;ensure&lt;/a&gt; that the interop assembly exists on the machine.  &lt;li&gt;Having IronPython automatically generate it on the fly - if you have a OLE automation object, IronPython tries to find its type library (TLB) and then to convert the TLB to an interop assembly on the fly using the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.typelibconverter(VS.80).aspx"&gt;TypeLibConverter&lt;/a&gt; class. The advantage is that this works seamlessly as long as there is a type library on the machine. The down-side is that this conversion can take a long time for large TLB files.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;This is how Word could be accessed in IronPython 1.X. It requires the interop assembly Microsoft.Office.Interop.Word.dll to be available on the machine.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;c:\&amp;gt;ipy.exe&lt;br&gt;IronPython 2.0 Beta (2.0.0.1000) on .NET 2.0.50727.1433&lt;br&gt;Copyright (c) Microsoft Corporation. All rights reserved.&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; import clr&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; clr.AddReference("Microsoft.Office.Interop.Word") # load interop assembly&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; from Microsoft.Office.Interop.Word import ApplicationClass&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; word = ApplicationClass() # load class defined in interop assembly&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; word.Visible = True # this works via CLR's COM interop support&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; doc = word.Documents.Add()&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; doc.Range().Text = "Hello from IronPython"&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; word.Quit()&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;h3&gt;IronPython 2.0&lt;/h3&gt; &lt;p&gt;IronPython 2.0 has added support for interacting with OLE automation objects using the IDispatch interface. This completely eliminates the need for interop assemblies. This is the same mechanism that &lt;a href="http://msdn2.microsoft.com/en-us/isv/bb190538.aspx"&gt;VBA&lt;/a&gt; late-bound code and also &lt;a href="http://msdn2.microsoft.com/en-us/library/9bbdkx3k.aspx"&gt;WSH&lt;/a&gt; use to interact with OLE automation object. This feature can currently be accessed using the -X:PreferComDispatch command line option.&lt;/p&gt; &lt;p&gt;Here is an interactive session showing access to Word. There are no interop assemblies in the picture.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;c:\&amp;gt;ipy.exe -X:PreferComDispatch&lt;br&gt;IronPython 2.0 Beta (2.0.0.1000) on .NET 2.0.50727.1433&lt;br&gt;Copyright (c) Microsoft Corporation. All rights reserved.&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; import clr&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; import System&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; wordTypeLibGuid = System.Guid("00020905-0000-0000-C000-000000000046")&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; clr.AddReferenceToTypeLibrary(wordTypeLibGuid)&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; from Word import Application&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; word = Application() # this uses Type.GetTypeFromCLSID and Activator.CreateInstance under the hood&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; word.Visible = True # this uses IDispatch.Invoke&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; doc = word.Documents.Add()&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; doc.Range().Text = "Hello from IronPython"&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; word.Quit()&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The feature is not complete yet, and so is not currently (April 08) enabled by default. The default behavior is still the same as IronPython 1.X. I can't say for sure when we will enable it by default, but its already quite stable for many real-world uses. We run all of our COM tests in both modes - using interop assemblies and using IDispatch. There are a few differences between the two cases in the minute details, but the mainline scenarios work well in both. This feature is implemented in the DLR, and so should be accessible from all DLR-based languages with little effort on the part of the language-implementors.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8376797" width="1" height="1"&gt;</description></item><item><title>What if a C# snippet does not work when transliterated to IronPython?</title><link>http://blogs.msdn.com/shrib/archive/2008/03/24/what-if-a-c-snippet-does-not-work-when-transliterated-to-ironpython.aspx</link><pubDate>Mon, 24 Mar 2008 21:54:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8334357</guid><dc:creator>shrib</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8334357.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8334357</wfw:commentRss><description>&lt;p&gt;Say you have a working piece of C# code. You want to include it in your IronPython app. So you transliterate it to IronPython code. And it stops working. What do you do?&lt;/p&gt; &lt;p&gt;You might feel lost at this point since the IronPython code is "supposed" to work. You have the following options:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;The first step ofcourse is to double-check your transliteration.&lt;/li&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;li&gt;The next step is simple but sometimes not obvious when you are in the middle of many other ongoing issues. This solution is to convert the C# code a function at a time to IronPython, or even a line at a time if needed. C# and IronPython can call each other very easily. So its easy to move small pieces of C# code over to IronPython. At every step, you check that the combined code works. You can use a binary search by speculatively moving bug chunks of code from C# to IronPython, and backing off when such a move exposes a problem. You will hopefully be able to narrow the problem down to a single line of IronPython code, which you can leave in C# until you figure out why IronPython cannot deal with it. &lt;/li&gt; &lt;p&gt;This isnt a perfect solution. Some problems can be non-deterministic, and the problem might repro at random times. However, in many cases, you will be able to narrow down the problem to a single line of IronPython code.&lt;/p&gt; &lt;li&gt;You could manually write C# code that uses Reflection.Emit to do the same work as the original C# code (once you have narrowed down the issue to a few line of code). IronPython code also gets compiled to Reflection.Emit code on the fly. Any issues that affect Reflection.Emit will be surfaced by your C# + Ref.Emit code.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8334357" width="1" height="1"&gt;</description></item><item><title>IronPython cannot call AutomationElement.FromHandle</title><link>http://blogs.msdn.com/shrib/archive/2008/03/24/ironpython-cannot-call-automationelement-fromhandle.aspx</link><pubDate>Mon, 24 Mar 2008 06:10:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8333079</guid><dc:creator>shrib</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shrib/comments/8333079.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=8333079</wfw:commentRss><description>&lt;p&gt;If you use IronPython to call &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.automation.automationelement.fromhandle.aspx"&gt;AutomationElement.FromHandle&lt;/a&gt;, it will return null. This happens because FromHandle uses &lt;a href="http://msdn2.microsoft.com/en-us/library/system.reflection.assembly.getcallingassembly(vs.85).aspx"&gt;Assembly.GetCallingAssembly&lt;/a&gt; and expects to get a statically compiled assembly with references to the correct version of the UIAutomation libraries. However, since IronPython code gets compiled on the fly using Reflection.Emit and DynamicMethods, it confuses AutomationElement.&lt;/p&gt; &lt;p&gt;This UIAutomation team knows about the issue and will be fixing it. I am not sure which particular release will have the fix. The workaround is to narrow down the specific call which is failing, and then perform that call from C#/VB.Net assembly.&lt;/p&gt; &lt;p&gt;I had added this comment to the Assembly.GetCallingAssembly docs. I am including it here to explain the details of the problem&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;The common case is for the caller to have directly called currently executing method. However, the caller may have invoked the currently executing method via a delegate, or in a late-bound way using MethodBase.Invoke. The delegate or the MethodInfo might have been created by one assembly, and then another assembly could have invoked it. GetCallingAssembly will not indicate who created the delegate or the MethodInfo. So if you use GetCallingAssembly to make security decisions, you will need to be extremely careful to ensure that you handle the cases of late-bound invocation. &lt;p&gt;Another unusual case is if the caller is a DynamicMethod. Since DynamicMethods can potentially be associated with arbitrary assemblies during creating, GetCallingAssembly will return the associated assembly.&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8333079" width="1" height="1"&gt;</description></item><item><title>Saving a file to the local disk in Silverlight</title><link>http://blogs.msdn.com/shrib/archive/2007/09/25/saving-a-file-to-the-local-disk-in-silverlight.aspx</link><pubDate>Tue, 25 Sep 2007 04:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5112256</guid><dc:creator>shrib</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/shrib/comments/5112256.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=5112256</wfw:commentRss><description>&lt;P&gt;All user code in Silverlight runs in a sandbox. Hence, for security reasons, there are no APIs to directly open local files from disk. However, there is a OpenFileDialog class which allows a Silverlight app to open files on disk. Human intervention is required to interact with the dialog box. This ensures that the user trusts the app to open the files selected in the dialog box.&lt;/P&gt;
&lt;P&gt;However, currently there is no equivalent to writing to a file to disk, even if the user wants to allow such an operation. This is unfortunate. If you implemented a text or image editor in Silverlight, the user would not be able to save the edited file to disk. However, there is a workaround -&amp;nbsp;but at the cost of extra network traffic. The solution involves the following steps:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The Silverlight client app running in the browser sends the data that needs to be saved to disk to the web server using a POST operation using System.Windows.Browser.Net.BrowerHttpWebRequest::GetResponse&lt;/LI&gt;
&lt;LI&gt;The web server saves the data to a temporary file and returns a URL for the temporary file in the response&lt;/LI&gt;
&lt;LI&gt;The Silverlight client app reads the URL that is returned in the System.Net.HttpWebResponse object.&lt;/LI&gt;
&lt;LI&gt;It navigates to the URL using System.Windows.Browser.HtmlPage::Navigate.&lt;/LI&gt;
&lt;LI&gt;This will result in the browser invoking the default action for the given file type. This is often to prompt the user to save the file to disk. If the browser opens the file directly, the user could then have the browser save the file to disk. If multiple files need to be saved, the web server could save them all in a zip file using System.IO.Compression.GZipStream.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;This solution is obviously not ideal as it result in unnecessarily sending the data back and forth over the network. For large files, this could be prohibitive. For small files, its a reasonable solution until there is a SaveFileDialog API in Silverlight.&lt;/P&gt;
&lt;P&gt;I do not know if there will be a SaveFileDialog in Silverlight 1.1, but I hear that the Silverlight team is looking into it...&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5112256" width="1" height="1"&gt;</description></item><item><title>Late-binding and ByRef parameters</title><link>http://blogs.msdn.com/shrib/archive/2007/09/10/late-binding-and-byref-parameters.aspx</link><pubDate>Mon, 10 Sep 2007 06:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4851583</guid><dc:creator>shrib</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shrib/comments/4851583.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=4851583</wfw:commentRss><description>&lt;P&gt;VB, VBA, and VBScript pass arguments by reference by default. A subroutine definition can explicitly override the default by specifying that a parameter should be passed by value. This does raise two issues in the face of late-binding:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;How are arbitrary expressions passed by reference? The answer is that expressions which cannot be the target of assignments, for eg, x + 1, get evaluated into a temporary, and the temp variable then gets passed byref to the subroutine. So any modifications to the temp variable are not noticeable to the user. See the sample below.&lt;/LI&gt;
&lt;LI&gt;How does a call-site determine if the target subroutine expects the argument as byref or byval. The answer is that the callsite cannot know. It always passes the arguments as byref. The target function then takes care of reading the value out of the byref parameter and storing it in a temporary variable. Any updates made by the body of the target function only affect the temp variable.&lt;/LI&gt;&lt;/OL&gt;
&lt;P mce_keep="true"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"&gt;Sub Foo(param)&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;param = "Foo"&lt;BR&gt;End Sub&lt;BR&gt;&lt;BR&gt;Sub AssertValue(actualValue, expectedValue)&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;If actualValue &amp;lt;&amp;gt; expectedValue Then&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MsgBox "Error! Expected " &amp;amp; expectedValue &amp;amp; " but got " &amp;amp; actualValue&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;End If&lt;BR&gt;End Sub&lt;BR&gt;&lt;BR&gt;Dim x&lt;BR&gt;&lt;BR&gt;x = 1&lt;BR&gt;Foo x&lt;BR&gt;AssertValue x, "Foo"&lt;BR&gt;&lt;BR&gt;x = 1&lt;BR&gt;Foo (x)&lt;BR&gt;AssertValue x, 1&lt;BR&gt;&lt;BR&gt;x = 1&lt;BR&gt;Foo x+1&lt;BR&gt;AssertValue x, 1&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4851583" width="1" height="1"&gt;</description></item><item><title>Oleview hangs on Vista when run from elevated cmd prompt</title><link>http://blogs.msdn.com/shrib/archive/2007/09/10/oleview-hangs-on-vista-when-run-from-elevated-cmd-prompt.aspx</link><pubDate>Mon, 10 Sep 2007 06:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4851419</guid><dc:creator>shrib</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shrib/comments/4851419.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=4851419</wfw:commentRss><description>&lt;P&gt;Oleview has been hanging and taking up all the CPU when I tried to open a typelib on a Vista machine. I saw &lt;A href="http://support.microsoft.com/kb/176938"&gt;http://support.microsoft.com/kb/176938&lt;/A&gt;&amp;nbsp;and tried to follow the recommended solution (regsvr32 iviewers.dll), but that did not fix it either. It turns out the solution is to run oleview from a non-elevated cmd prompt. For example, you can just run it from the Run dialog box. I was always running it from an elevated cmd prompt since that's what I am have open for during development.&lt;/P&gt;
&lt;P&gt;You wouldn't think that something that works in non-elevated mode would break in elevated mode, but apparantly it happens because of some registry shimming...&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4851419" width="1" height="1"&gt;</description></item><item><title>Using IReflect to expose a type as IDispatch to COM</title><link>http://blogs.msdn.com/shrib/archive/2007/09/04/ireflect-and-idispatch.aspx</link><pubDate>Tue, 04 Sep 2007 23:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4750783</guid><dc:creator>shrib</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shrib/comments/4750783.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=4750783</wfw:commentRss><description>&lt;P&gt;The CLR supports marshalling of objects that support the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.reflection.ireflect.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.reflection.ireflect.aspx"&gt;IReflect&lt;/A&gt; interface as &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms221608.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms221608.aspx"&gt;IDispatch&lt;/A&gt; COM objects. Similarly, &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.expando.iexpando.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.expando.iexpando.aspx"&gt;IExpando&lt;/A&gt; gets marshalled as &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/sky96ah7.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/sky96ah7.aspx"&gt;IDispatchEx&lt;/A&gt;. Here is a sample of a managed type called &lt;FONT size=2&gt;ManagedIDispatch &lt;/FONT&gt;which is used from VBScript and used in a late-bound way. VBScript just deals with IDispatch, and under the hoods, the CLR routes the calls to the IReflect methods implemented by ManagedIDispatch, and also takes care of providing a stable mapping between method names and dispids.&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.reflection.ireflect.getmethods.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.reflection.ireflect.getmethods.aspx"&gt;IReflect.GetMethods&lt;/A&gt; gets called every time COM instantiates the&amp;nbsp;managed type. The CLR caches the method names for the given object, and the names are then available to COM from the IDispatch interface. If COM accesses a method name that is not in the cached list, IReflect.GetMethods get called again.&lt;/P&gt;
&lt;P&gt;The C# code should be compiled and registered as:&lt;/P&gt;&lt;FONT color=#008000 size=2&gt;
&lt;P&gt;csc /t:library ManagedIDispatch.cs&lt;/P&gt;
&lt;P&gt;regasm /codebase ManagedIDispatch.dll&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;Here is the significant contents of ManagedIDispatch.cs&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt;&lt;FONT color=#000000&gt; ManagedIDispatch : &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IReflect&lt;/SPAN&gt;&lt;FONT color=#000000&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MethodInfo&lt;/SPAN&gt;&lt;FONT color=#000000&gt;[] GetMethods(&lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;BindingFlags&lt;/SPAN&gt;&lt;FONT color=#000000&gt; bindingAttr) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;FONT color=#000000&gt;.WriteLine(&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"In ManagedIDispatch.GetMethods (_getMethodsDone={0})"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;, _getMethodsDone);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// dynFoo is a method that is not always present&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;&lt;FONT color=#000000&gt; (_getMethodsDone) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MethodInfo&lt;/SPAN&gt;&lt;FONT color=#000000&gt;[] methods = &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MethodInfo&lt;/SPAN&gt;&lt;FONT color=#000000&gt;[_methodInfos.Length + 1];&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_methodInfos.CopyTo(methods, 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;methods[_methodInfos.Length] = &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&lt;FONT color=#000000&gt; MyMethodInfo(&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"dynFoo"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; methods;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;} &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;FONT color=#000000&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_getMethodsDone = &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;&lt;FONT color=#000000&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; _methodInfos;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;FONT color=#000000&gt; InvokeMember(&lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; name, &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;BindingFlags&lt;/SPAN&gt;&lt;FONT color=#000000&gt; invokeAttr, &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Binder&lt;/SPAN&gt;&lt;FONT color=#000000&gt; binder, &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;FONT color=#000000&gt; target, &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&lt;FONT color=#000000&gt;[] args, &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ParameterModifier&lt;/SPAN&gt;&lt;FONT color=#000000&gt;[] modifiers, &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;&lt;FONT color=#000000&gt; culture, &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt;[] namedParameters) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;FONT color=#000000&gt;.WriteLine(&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"In ManagedIDispatch.InvokeMember({0} : {1})"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;, name, GetArgs(target, args));&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;switch&lt;/SPAN&gt;&lt;FONT color=#000000&gt; (name) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;case&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"[DISPID=0]"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;: &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;&lt;FONT color=#000000&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;case&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"raiseException"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;: &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Exception&lt;/SPAN&gt;&lt;FONT color=#000000&gt;(&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"raiseException has been invoked"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;case&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"foo"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;: &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"foo-return"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;case&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"dynFoo"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;: Debug.Assert(_getMethodsDone);&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"dynFoo-return"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;default&lt;/SPAN&gt;&lt;FONT color=#000000&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;&lt;FONT color=#000000&gt; (name == (&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"bar"&lt;/SPAN&gt;&lt;FONT color=#000000&gt; + _index)) &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"bar-return"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&lt;FONT color=#000000&gt; Utils.NotImplemented(&lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"This is unreachable"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri color=#000000 size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;/SPAN&gt;Here is the VBScript used to script the type: 
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;Sub AssertError(errNum, errDescr)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Err.Number &amp;lt;&amp;gt; errNum Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Error number is incorrect:" &amp;amp; Err.Number &amp;amp; ", expected " &amp;amp; errNum&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Err.Description &amp;lt;&amp;gt; errDescr Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Error description is incorrect:" &amp;amp; Err.Description &amp;amp; ", expected " &amp;amp; errDescr&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Err.Clear&lt;BR&gt;End Sub&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;c1 = CreateObject("TestFactory")&lt;BR&gt;m = c1.GetManagedObject()&lt;BR&gt;m.foo()&lt;BR&gt;m.dynFoo()&lt;BR&gt;m.bar0()&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;On Error Resume Next&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;m.nonexistent()&lt;BR&gt;AssertError 438, "Object doesn't support this property or method"&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT size=2&gt;m.raiseException()&lt;BR&gt;AssertError -2146233088, "" ' 0x80131500 : CLR exception&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;/P&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;
&lt;P mce_keep="true"&gt;The output of the script is:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;&lt;FONT size=3&gt;c:\bugs&amp;gt;cscript vbs1.vbs&lt;BR&gt;Microsoft (R) Windows Script Host Version 5.7&lt;BR&gt;Copyright (C) Microsoft Corporation. All rights reserved.&lt;BR&gt;&lt;BR&gt;In ManagedIDispatch.GetMethods (_getMethodsDone=False)&lt;BR&gt;In MyMethodInfo.Name.get(foo)&lt;BR&gt;In MyMethodInfo.Name.get(bar0)&lt;BR&gt;In MyMethodInfo.Name.get(raiseException)&lt;BR&gt;In ManagedIDispatch.InvokeMember([DISPID=0] : ManagedIDispatch)&lt;BR&gt;In ManagedIDispatch.InvokeMember(foo : ManagedIDispatch)&lt;BR&gt;In ManagedIDispatch.GetMethods (_getMethodsDone=True)&lt;BR&gt;In MyMethodInfo.Name.get(dynFoo)&lt;BR&gt;In ManagedIDispatch.InvokeMember(dynFoo : ManagedIDispatch)&lt;BR&gt;In ManagedIDispatch.InvokeMember(bar0 : ManagedIDispatch)&lt;BR&gt;In ManagedIDispatch.GetMethods (_getMethodsDone=True)&lt;BR&gt;In MyMethodInfo.Name.get(dynFoo)&lt;BR&gt;In ManagedIDispatch.InvokeMember(raiseException : ManagedIDispatch)&lt;/FONT&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4750783" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/shrib/attachment/4750783.ashx" length="6427" type="text/plain" /></item><item><title>Tail call performance on x86</title><link>http://blogs.msdn.com/shrib/archive/2005/01/25/360370.aspx</link><pubDate>Tue, 25 Jan 2005 20:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:360370</guid><dc:creator>shrib</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/shrib/comments/360370.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shrib/commentrss.aspx?PostID=360370</wfw:commentRss><description>&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;MSIL includes the &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;tail.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; prefix to be used with call instructions (&lt;/SPAN&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;call, callvirt, calli&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;), and also the specialized form &lt;/SPAN&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;jmp&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;. The &lt;/SPAN&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;tail.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; prefix is a hint that the stack frame of the current method should be popped from the stack before transferring control to the target of the call. This is important for &lt;A href="http://en.wikipedia.org/wiki/Functional_programming"&gt;functional languages&lt;/A&gt; like Scheme which &lt;A href="http://en.wikipedia.org/wiki/Tail_recursion"&gt;rely on recursion&lt;/A&gt;. Without tail calls, they would run into StackOverflows on a routine basis.&lt;/SPAN&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;The CLR implementation of tail calls on x86 is not the most optimal it could be. We &lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-STYLE: italic; mso-bidi-font-style: normal"&gt;have&lt;/SPAN&gt;&lt;/I&gt; improved the performance of tail calls in Whidbey (V2). Most tail calls are about 50% faster. However, there is still some work to be done. This blog explains why implementing tail calls is not as straight-forward as it might seem.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;The CLR has an accurate tracing Garbage collector - as opposed to a conservative one like the &lt;A href="http://www.hpl.hp.com/personal/Hans_Boehm/gc/"&gt;Boehm collector&lt;/A&gt;. This puts some requirements on the native code compiled from the IL, and also on the tracking information corresponding to it (similar to pdata on RISC platforms). One of the requirements is that the CLR be able to determine exactly where the return address of the method is on the stack. This is required so that the CLR can “hijack” the return address by temporarily overwriting it with the address of one of the hijacking function in the CLR. This is done so the CLR will get control when the method returns, and the CLR can perform a garbage-collection.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;This requirement makes it difficult to move the return address around. Moving the return address around is needed while doing a tail call to a method with a different number of stack-based arguments as the return address gets pushed after the stack arguments. The following diagram shows how the stack looks at various points when a method &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;foo&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; is called normally, and it does a tail call to &lt;/SPAN&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;bar&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; which expects a different number of arguments on the stack. Note that the return address needs to be moved by &lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;foo&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; &lt;/SPAN&gt;before it does the tail call.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt"&gt;&lt;FONT face="Courier New" size=1&gt;&amp;nbsp;As soon as foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; While foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; When foo is about to&lt;BR&gt;&amp;nbsp;&amp;nbsp; is called&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is executing&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tail call to bar&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt"&gt;&lt;FONT face="Courier New" size=1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | foo's frame&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |return address|&lt;BR&gt;+--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&lt;BR&gt;|return address|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |return address|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;+--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;| stack args&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | stack args&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | stack args&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp; of foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; of foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; of bar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;+--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +--------------+&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp; Frame of&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; Frame of&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; Frame of&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|foo's caller&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |foo's caller&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |foo's caller&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;BR&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Furthermore, we tend to be really careful when changing the hijacking code as any bugs introduced in this code are not easily caught, and instead can become GC holes (corrupt GC references). Most programs will seem to work fine, but if a GC is triggered at just the right spot, some poor object reference will get corrupted.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Another (secondary) concern is GC starvation. If two methods recursively tail call to each other, it causes an infinite loop and the hijacking mechanism does not get a chance to kick in. This reduces the opportunity for GC to suspend the thread and do a collection. This could cause other threads to block longer while they wait for GC to free up some heap memory.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;We do know how to make this even faster, and would have loved to have fixed this. However, because of schedule pressure and the risk associated, further improvements will have to wait until after Whidbey (V2.0).&lt;/SPAN&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;FWIW, the &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;jmp&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; IL instruction is faster since the return address does not have to be shuffled in this case. Also, tail calls will be much faster on 64-bit platforms as the arguments for most methods fit in registers (and so the return address does not need to be moved around). In fact, on 64-bit platforms, the CLR tries to do tail calls even if the &lt;/SPAN&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;tail.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt; prefix is not specified. This is because platform-independent IL programs will get the same amount of stack space reserved for them by the OS, even though the 64-bit process will consume stack at a faster rate. Hence, we try to reduce stack usage by doing tail calls.&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=360370" width="1" height="1"&gt;</description></item></channel></rss>