Friday, September 10, 2010

Anonymous function as default argument in methods

I was quite surprised by Python recently when I tried to use anonymous function that uses a class method (not classmethod) as a default argument for another class method and it worked. Example is worth thousands words so here it is:
class ListObject(object):
    items = ((1, 'one'), (2, 'two'), (3, 'three'))

    def get_num(self, item):
        return item[0]

    def get_text(self, item):
        return item[1]

    def get_list(self, fn=lambda s, i: ListObject.get_num(s, i)):
        return [fn(self, j) for j in self.items]

lo = ListObject()
print 'numbers:', lo.get_list()
print 'texts:', lo.get_list(ListObject.get_text)
print 'texts:', lo.get_list(lambda s, i: i[1])
print 'items:', lo.get_list(lambda s, i: i)
When you run this piece of code you get what you want:
numbers: [1, 2, 3]
texts: ['one', 'two', 'three']
texts: ['one', 'two', 'three']
items: [(1, 'one'), (2, 'two'), (3, 'three')]
By default, get_list method uses get_num method and apply it to all items. But you can supply your own fucntion to apply it on items.

Of course, this is very stupid example but it shows the principle. And this principle is quite handy for UI automation I am currently working on :-)

Sunday, May 16, 2010

Distributing Silverlight application written in IronPython

When you have Silverlight application written in IronPython, it is a good idea to split it to several files so browser can cache them separately. Later, when you change something in your application, users will download only a small part. During my attemts with IronPython and Silverligt, I have found several catches. That's why I describe here my way how to distribute IronPython Silverlight application.

I distribute my application as one .html file, one .xap file, and several .zip files. I use .zip because IIS already knows what to do with .zip files. The files are:

  1. index.html
  2. app.xap
  3. IronPython.zip - contains files from IronPython-2.6.1\Silverlight\bin:
    IronPython.dll
    IronPython.Modules.dll
    
  4. Microsoft.Scripting.zip - contains files from IronPython-2.6.1\Silverlight\bin:
    Microsoft.Dynamic.dll
    Microsoft.Scripting.dll
    Microsoft.Scripting.Core.dll
    Microsoft.Scripting.ExtensionAttribute.dll
    Microsoft.Scripting.Silverlight.dll
    
  5. SLToolkit.zip - contains files form Silverlight toolkit or SDK; in our case just
  6. System.Windows.Controls.dll
    

Let's create a small application, that uses ChildWindow control from Silverlight toolkit:

C:\IronPython-2.6.1\Silverlight\script\sl.bat python childwindow
Change the app.py and app.xml:

app.py

from System.Windows import Application
from System.Windows.Controls import UserControl

class App:
    def __init__(self):
        self.root = Application.Current.LoadRootVisual(UserControl(), "app.xaml")

a = App()

app.xaml

<UserControl x:Class="System.Windows.Controls.UserControl"
  xmlns="http://schemas.microsoft.com/client/2007"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">
  <controls:ChildWindow >
    <StackPanel>
      <TextBlock Text="Text in ChildWindow"/>
      <Button x:Name="btnNewWindow" Content="New window"/>
    </StackPanel>
  </controls:ChildWindow>
</UserControl>

We don't want to Chiron automatically add necesary .dll files into .xap so we have to add our own AppManifest.xaml and languages.config into childwindow\app folder:

AppManifest.xaml

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  RuntimeVersion="2.0.31005.0"
  EntryPointAssembly="Microsoft.Scripting.Silverlight"
  EntryPointType="Microsoft.Scripting.Silverlight.DynamicApplication"
  ExternalCallersFromCrossDomain="ScriptableOnly">
  <Deployment.Parts>
  </Deployment.Parts>
  <Deployment.ExternalParts>
    <ExtensionPart Source="Microsoft.Scripting.zip" />
    <ExtensionPart Source="SLToolkit.zip" />
  </Deployment.ExternalParts>
</Deployment>

languages.config

<Languages>
  <Language names="IronPython,Python,py"
    languageContext="IronPython.Runtime.PythonContext"
    extensions=".py"
    assemblies="IronPython.dll;IronPython.Modules.dll"
    external="IronPython.zip"/>
</Languages>

Now create all three .zip files and add them into childwindow folder.

To test the application with Chiron, run

C:\IronPython-2.6.1\Silverlight\bin\Chiron.exe /e: /d:childwindow

The /e: switch is important - it tells Chiron to not put any assembly into generated .xap file. Check the application on http://localhost:2060/index.html.

To generate .xap file for distribution, run:

C:\IronPython-2.6.1\Silverlight\bin\Chiron.exe /e: /d:childwindow\app /z:app.zap

If you want to use anything from external assemblies in the code, you have to add manually reference to those assemblies. For example, if you want to add a button that creates a new ChildWindow, you have to change you code like this:

app.py

from System.Windows import Application
from System.Windows.Controls import UserControl

class App:
    def __init__(self):
        self.root = Application.Current.LoadRootVisual(UserControl(), "app.xaml")
        self.root.btnNewWindow.Click += self.OnClick

    def OnClick(self, sender, event):
        import clr
        clr.AddReference('System.Windows.Controls')
        from System.Windows.Controls import ChildWindow
        self.root.panel.Children.Add(ChildWindow(Content='new window'))

a = App()

app.xaml

<UserControl x:Class="System.Windows.Controls.UserControl"
  xmlns="http://schemas.microsoft.com/client/2007"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">
  <controls:ChildWindow >
    <StackPanel x:Name="panel">
      <TextBlock Text="Text in ChildWindow"/>
      <Button x:Name="btnNewWindow" Content="New window"/>
    </StackPanel>
  </controls:ChildWindow>
</UserControl>

If you comment out the clr.AddReference line, ImportError appears. See the explanation in Jimmy's email.

You can download the example here but note the .zip files do not contain and .dlls.

Wednesday, May 12, 2010

Silverlight validation with IronPython

Validation support in Silverlight is done via Visual State Manager. All invalid fields have red rectangle around themselves. Unfortunately, this does not work out of the box in IronPython. We have to push it a little bit.

To demonstrate how, I have created a small example. Create a Silverlight app template and change app.py and app.xaml:

C:\IronPython-2.6.1\Silverlight\script\sl.bat python validation
app.py
import clrtype
import pyevent
from System.Windows import Application
from System.Windows.Controls import UserControl
from System.ComponentModel import INotifyPropertyChanged, PropertyChangedEventArgs

class ValidationClass(INotifyPropertyChanged):
    __metaclass__ = clrtype.ClrClass
    PropertyChanged = None

    def __init__(self, win):
        self.win = win
        self._text = 'text'
        self.PropertyChanged, self._propertyChangedCaller = pyevent.make_event()

    def add_PropertyChanged(self, value):
        self.PropertyChanged += value

    def remove_PropertyChanged(self, value):
        self.PropertyChanged -= value

    def OnPropertyChanged(self, propertyName):
        if self.PropertyChanged is not None:
            self._propertyChangedCaller(self, PropertyChangedEventArgs(propertyName))

    @property
    @clrtype.accepts()
    @clrtype.returns(str)
    def text(self):
        return self._text

    @text.setter
    @clrtype.accepts(str)
    @clrtype.returns()
    def text(self, value):
        if not value.startswith('text'):
            raise Exception('Value must start with text!')
        self._text = value
        self.OnPropertyChanged('text')

class App:
    def __init__(self):
        self.root = Application.Current.LoadRootVisual(UserControl(), "app.xaml")
        self.root.DataContext = ValidationClass(self.root)

App()
app.xaml
<UserControl x:Class="System.Windows.Controls.UserControl"
  xmlns="http://schemas.microsoft.com/client/2007"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
    <TextBox x:Name="tbValidate1" Width="100" Height="25" 
      Text="{Binding text, Mode=TwoWay, ValidatesOnExceptions=True,
      NotifyOnValidationError=True}" />
    <TextBox Width="100" Height="25" />
    <TextBlock Text="{Binding text}" HorizontalAlignment="Center" />
  </StackPanel>
</UserControl>

When you run this application (C:\IronPython-2.6.1\Silverlight\script\server.bat /d:validation), you'll find out the validation does not work. There is no red rectangle when you enter wrong value; e.g. wrong.

Note the second empty TextBox is there so you can move focus out of the first one to update bound property.

For whatever reason, the invalid component is not switched into invalid state. Could be IronPython bug, could be something else. Anyway to fix it, you have to switch the control into invalid state manually. Add the BindingValidationError event:

from System.Windows import VisualStateManager
from System.Windows.Controls import ValidationErrorEventAction

...

class App:
    def __init__(self):
        self.root = Application.Current.LoadRootVisual(UserControl(), "app.xaml")
        self.root.DataContext = ValidationClass(self.root)
        self.root.BindingValidationError += self.OnBindingValidationError

    def OnBindingValidationError(self, sender, event):
        if event.Action == ValidationErrorEventAction.Added:
            VisualStateManager.GoToState(event.OriginalSource, 'InvalidUnfocused', True)
        else:
            VisualStateManager.GoToState(event.OriginalSource, 'Valid', True

Now when you enter wrong value into TextBox, you can see red rectangle around the control. You also see, the bound variable has the old, correct value text:

You can download the whole source here.

Tuesday, March 16, 2010

Parsing XML with XDocument

I needed to parse a XML document recently in Silverlight. Unfortunately, Silverlight does not have System.Xml.XmlDocument type so you need to use System.Xml.Linq.XDocument.

The following example works in Silverlight and with small change also in WPF.

# encoding: utf-8
import clr
clr.AddReferenceToFile('System.Xml.Linq.dll')
from System.Xml.Linq import XDocument, XNamespace

content = """<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss"
    xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <item>
            <title>This is the title</title>
            <media:description type="html"><p></p></media:description>
            <link>html/dsc00001.html</link>
            <media:thumbnail url="preview/dsc00001.jpg"/>
            <media:content url="web/dsc00001.jpg"/>
        </item>
        <item>
            <title></title>
            <media:description type="html"><p></p></media:description>
            <link>html/dsc00002.html</link>
            <media:thumbnail url="preview/dsc00002.jpg"/>
            <media:content url="web/dsc00002.jpg"/>
        </item>
    </channel>
</rss>"""

xDoc = XDocument().Parse(content)
namespace = XNamespace.Get("http://search.yahoo.com/mrss")
for item in xDoc.Element('rss').Element('channel').Elements('item'):
    print item.Element('title').Value
    print item.Element(namespace+'thumbnail').Attribute('url').Value
Here is the output:
This is the title
preview/dsc00001.jpg

preview/dsc00002.jpg

You have to have System.Xml.Linq.dll from Silverlight SDK next to your app.py.

The change for WPF:

clr.AddReference('System.Xml.Linq')

Also make sure you don't have Silverlight's System.Xml.Linq.dll next to your script.

Tuesday, February 23, 2010

Disk Encryption in OpenWrt

I have an external USB disk connected to my Asus WL-500gP which runs OpenWrt KAMIKAZE (8.09.1, r16278).

I want to have the disk encrypted. So I installed every possible package that has aes or loop in name but I still got the following error message:

root@OpenWrt:~# losetup -e aes /dev/loop/0 /dev/scsi/host0/bus0/target0/lun0/part1
Password:
ioctl: LOOP_SET_STATUS: Invalid argument

The solution was easy - install losetup that supports aes encryption. You can find the package on http://www.roth.lu/download/openwrt-usb-raid1-loopaes/. Download it, install it and viola - it works :-)

root@OpenWrt:~# losetup -e aes /dev/loop/0 /dev/scsi/host0/bus0/target0/lun0/part1
Password:
root@OpenWrt:~# mkfs.ext2 -vm0 /dev/loop/0
mkdir /mnt/disk/
mount /dev/loop/0 /mnt/disc
To mount the disc in script use
echo password | losetup -e aes /dev/loop/0 /dev/scsi/host0/bus0/target0/lun0/part1 -p0

Thursday, January 21, 2010

WinDbg for beginners

A few days ago I have encountered a strange problem. When I copied IronPython.Modules.dll to my application's folder, it freezed. Strange. It looked like a bug in IronPython for me but it wasn't. With Dino Viehland help, I have found the bug in Delphi code. Dino used WinDbg to discover what is going on in the code. I show you it is not so hard to use it.

WinDbg is part of Debuging Tolls for Windows. Download and install appropriate version for your Windows (32 or 64 bit). And download the bugged application.

The IpyTest.exe is Delphi 7 application that creates the CLR and runs function Add3 from Host.dll inside the CLR. The Add3 function creates IronPython engine and returns result of adding number 3 to the input variabl. So when you run IpyTest.exe you should see

C:\IronPythonBug\Delphi>IpyTest.exe
CLRVersion = v2.0.50727
8 + 3 = 11

You may actually see it because this bug does not appear on all computers. But on mine, I see just the CLRVersion. Then the program freezes.

Let's debug the application in WinDbg:

"C:\Program Files\Debugging Tools for Windows (x86)\windbg.exe" C:\IronPythonBug\Delphi\IpyTest.exe

When WinDbg and IpyTest.exe start, you see this:


Enter the following commands:

0:000> sxe clr
0:000> sxe av
0:000> .symfix
0:000> .reload
Reloading current modules
............

If you want to know what these commands do, check the help :-) Then run the debugger with g command. It runs for a while and then it freezes with the following output:

0:000> g
ModLoad: 76390000 763ad000   C:\WINDOWS\system32\IMM32.DLL
ModLoad: 79000000 79046000   C:\WINDOWS\system32\mscoree.dll
ModLoad: 77f60000 77fd6000   C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 79e70000 7a400000   c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
ModLoad: 78130000 781cb000   C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.3053_x-ww_b80fa8ca\MSVCR80.dll
ModLoad: 7c9c0000 7d1d7000   C:\WINDOWS\system32\shell32.dll
ModLoad: 773d0000 774d3000   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll
ModLoad: 5d090000 5d12a000   C:\WINDOWS\system32\comctl32.dll
ModLoad: 790c0000 79bb7000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\6d667f19d687361886990f3ca0f49816\mscorlib.ni.dll
ModLoad: 79060000 790bb000   c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
ModLoad: 33200000 3322c000   Microsoft.Scripting.dll
ModLoad: 68000000 68036000   C:\WINDOWS\system32\rsaenh.dll
ModLoad: 64020000 64033000   c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorsec.dll
ModLoad: 76c30000 76c5e000   C:\WINDOWS\system32\WINTRUST.dll
ModLoad: 77a80000 77b15000   C:\WINDOWS\system32\CRYPT32.dll
ModLoad: 77b20000 77b32000   C:\WINDOWS\system32\MSASN1.dll
ModLoad: 76c90000 76cb8000   C:\WINDOWS\system32\IMAGEHLP.dll
ModLoad: 74e30000 74e9d000   C:\WINDOWS\system32\RichEd20.dll
ModLoad: 04a30000 04cf5000   C:\WINDOWS\system32\xpsp2res.dll
ModLoad: 769c0000 76a74000   C:\WINDOWS\system32\userenv.dll
ModLoad: 5b860000 5b8b5000   C:\WINDOWS\system32\netapi32.dll
ModLoad: 75e60000 75e73000   C:\WINDOWS\system32\cryptnet.dll
ModLoad: 76bf0000 76bfb000   C:\WINDOWS\system32\PSAPI.DLL
ModLoad: 722b0000 722b5000   C:\WINDOWS\system32\SensApi.dll
ModLoad: 4d4f0000 4d549000   C:\WINDOWS\system32\WINHTTP.dll
ModLoad: 76f60000 76f8c000   C:\WINDOWS\system32\WLDAP32.dll
ModLoad: 33200000 3322c000   C:\IronPythonBug\Delphi\Microsoft.Scripting.dll
ModLoad: 34700000 34860000   IronPython.dll
ModLoad: 34700000 34860000   C:\IronPythonBug\Delphi\IronPython.dll
ModLoad: 33000000 33064000   Microsoft.Scripting.Core.dll
ModLoad: 33000000 33064000   C:\IronPythonBug\Delphi\Microsoft.Scripting.Core.dll
ModLoad: 7a440000 7abc5000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\80978a322d7dd39f0a71be1251ae395a\System.ni.dll
ModLoad: 33400000 334dc000   Microsoft.Dynamic.dll
ModLoad: 33400000 334dc000   C:\IronPythonBug\Delphi\Microsoft.Dynamic.dll
ModLoad: 73000000 73008000   Microsoft.Scripting.ExtensionAttribute.dll
ModLoad: 73000000 73008000   C:\IronPythonBug\Delphi\Microsoft.Scripting.ExtensionAttribute.dll
ModLoad: 34c10000 34c80000   IronPython.Modules.dll
ModLoad: 34c10000 34c80000   C:\IronPythonBug\Delphi\IronPython.Modules.dll
ModLoad: 64890000 64981000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\b82c00e2d24305ad6cb08556e3779b75\System.Configuration.ni.dll
ModLoad: 637a0000 63cd6000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\773a9786013451d3baaeff003dc4230f\System.Xml.ni.dll
(b6c.ef0): Unknown exception - code c0000091 (first chance)

>>> many lines omitted <<<

(b6c.ef0): Unknown exception - code c0000091 (first chance)

The IpyTest.exe window contains just a text: CLRVersion = v2.0.50727. Break the debugger with Ctrl-Break. We see there is an unknown exception with code c0000091. Let's restart the program and tell WinDbg to stop on this exception with the following commands:

.restart
sxe c0000091
.symfix
.reload
g

Here is the output:

0:003> .restart
CommandLine: C:\IronPythonBug\Delphi\IpyTest.exe
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00400000 00455000   image00400000
ModLoad: 7c900000 7c9af000   ntdll.dll
ModLoad: 7c800000 7c8f6000   C:\WINDOWS\system32\kernel32.dll
ModLoad: 7e410000 7e4a1000   C:\WINDOWS\system32\user32.dll
ModLoad: 77f10000 77f59000   C:\WINDOWS\system32\GDI32.dll
ModLoad: 77dd0000 77e6b000   C:\WINDOWS\system32\advapi32.dll
ModLoad: 77e70000 77f02000   C:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77fe0000 77ff1000   C:\WINDOWS\system32\Secur32.dll
ModLoad: 77120000 771ab000   C:\WINDOWS\system32\oleaut32.dll
ModLoad: 77c10000 77c68000   C:\WINDOWS\system32\msvcrt.dll
ModLoad: 774e0000 7761d000   C:\WINDOWS\system32\ole32.dll
ModLoad: 77c00000 77c08000   C:\WINDOWS\system32\version.dll
(ea8.a14): Break instruction exception - code 80000003 (first chance)
eax=00351ec4 ebx=7ffd4000 ecx=00000004 edx=00000010 esi=00351f98 edi=00351ec4
eip=7c90120e esp=0012fb20 ebp=0012fc94 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
ntdll!DbgBreakPoint:
7c90120e cc              int     3
0:000> sxe c0000091
0:000> .symfix
0:000> .reload
Reloading current modules
............
0:000> g
ModLoad: 76390000 763ad000   C:\WINDOWS\system32\IMM32.DLL
ModLoad: 79000000 79046000   C:\WINDOWS\system32\mscoree.dll
ModLoad: 77f60000 77fd6000   C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 79e70000 7a400000   c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
ModLoad: 78130000 781cb000   C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.3053_x-ww_b80fa8ca\MSVCR80.dll
ModLoad: 7c9c0000 7d1d7000   C:\WINDOWS\system32\shell32.dll
ModLoad: 773d0000 774d3000   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll
ModLoad: 5d090000 5d12a000   C:\WINDOWS\system32\comctl32.dll
ModLoad: 790c0000 79bb7000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\6d667f19d687361886990f3ca0f49816\mscorlib.ni.dll
ModLoad: 79060000 790bb000   c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
ModLoad: 33200000 3322c000   Microsoft.Scripting.dll
ModLoad: 68000000 68036000   C:\WINDOWS\system32\rsaenh.dll
ModLoad: 64020000 64033000   c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorsec.dll
ModLoad: 76c30000 76c5e000   C:\WINDOWS\system32\WINTRUST.dll
ModLoad: 77a80000 77b15000   C:\WINDOWS\system32\CRYPT32.dll
ModLoad: 77b20000 77b32000   C:\WINDOWS\system32\MSASN1.dll
ModLoad: 76c90000 76cb8000   C:\WINDOWS\system32\IMAGEHLP.dll
ModLoad: 74e30000 74e9d000   C:\WINDOWS\system32\RichEd20.dll
ModLoad: 04a30000 04cf5000   C:\WINDOWS\system32\xpsp2res.dll
ModLoad: 769c0000 76a74000   C:\WINDOWS\system32\userenv.dll
ModLoad: 5b860000 5b8b5000   C:\WINDOWS\system32\netapi32.dll
ModLoad: 75e60000 75e73000   C:\WINDOWS\system32\cryptnet.dll
ModLoad: 76bf0000 76bfb000   C:\WINDOWS\system32\PSAPI.DLL
ModLoad: 722b0000 722b5000   C:\WINDOWS\system32\SensApi.dll
ModLoad: 4d4f0000 4d549000   C:\WINDOWS\system32\WINHTTP.dll
ModLoad: 76f60000 76f8c000   C:\WINDOWS\system32\WLDAP32.dll
ModLoad: 33200000 3322c000   C:\IronPythonBug\Delphi\Microsoft.Scripting.dll
ModLoad: 34700000 34860000   IronPython.dll
ModLoad: 34700000 34860000   C:\IronPythonBug\Delphi\IronPython.dll
ModLoad: 33000000 33064000   Microsoft.Scripting.Core.dll
ModLoad: 33000000 33064000   C:\IronPythonBug\Delphi\Microsoft.Scripting.Core.dll
ModLoad: 7a440000 7abc5000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\80978a322d7dd39f0a71be1251ae395a\System.ni.dll
ModLoad: 33400000 334dc000   Microsoft.Dynamic.dll
ModLoad: 33400000 334dc000   C:\IronPythonBug\Delphi\Microsoft.Dynamic.dll
ModLoad: 73000000 73008000   Microsoft.Scripting.ExtensionAttribute.dll
ModLoad: 73000000 73008000   C:\IronPythonBug\Delphi\Microsoft.Scripting.ExtensionAttribute.dll
ModLoad: 34c10000 34c80000   IronPython.Modules.dll
ModLoad: 34c10000 34c80000   C:\IronPythonBug\Delphi\IronPython.Modules.dll
ModLoad: 64890000 64981000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\b82c00e2d24305ad6cb08556e3779b75\System.Configuration.ni.dll
ModLoad: 637a0000 63cd6000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\773a9786013451d3baaeff003dc4230f\System.Xml.ni.dll
(ea8.a14): Unknown exception - code c0000091 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=ffffff00 ebx=02643d64 ecx=02640010 edx=02648e3c esi=02643bd4 edi=02640010
eip=79098f48 esp=0012ce30 ebp=0012ce34 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00010202
mscorjit!Compiler::FlatFPIsSameAsFloat+0xa:
79098f48 d945fc          fld     dword ptr [ebp-4]    ss:0023:0012ce30=02640010

WinDbg stopped on the exception. Nice. And what now? Analyze the exception!

0:000> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\6d667f19d687361886990f3ca0f49816\mscorlib.ni.dll
*** WARNING: Unable to verify checksum for image00400000
*** ERROR: Module load completed but symbols could not be loaded for image00400000
*** ERROR: Module load completed but symbols could not be loaded for C:\WINDOWS\system32\xpsp2res.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\IronPythonBug\Delphi\Microsoft.Scripting.Core.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\IronPythonBug\Delphi\Microsoft.Scripting.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\IronPythonBug\Delphi\Microsoft.Dynamic.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\IronPythonBug\Delphi\IronPython.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\IronPythonBug\Delphi\IronPython.Modules.dll
*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\773a9786013451d3baaeff003dc4230f\System.Xml.ni.dll
*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\b82c00e2d24305ad6cb08556e3779b75\System.Configuration.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\IronPythonBug\Delphi\Microsoft.Scripting.ExtensionAttribute.dll
*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\80978a322d7dd39f0a71be1251ae395a\System.ni.dll
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************

FAULTING_IP: 
mscorjit!Compiler::FlatFPIsSameAsFloat+7
79098f45 d95dfc          fstp    dword ptr [ebp-4]

EXCEPTION_RECORD:  ffffffff -- (.exr 0xffffffffffffffff)
ExceptionAddress: 79098f45 (mscorjit!Compiler::FlatFPIsSameAsFloat+0x00000007)
   ExceptionCode: c0000091
  ExceptionFlags: 00000000
NumberParameters: 1
   Parameter[0]: 00000000

FAULTING_THREAD:  00000a14

DEFAULT_BUCKET_ID:  WRONG_SYMBOLS

PROCESS_NAME:  image00400000

ERROR_CODE: (NTSTATUS) 0xc0000091 - {EXCEPTION}  Floating-point overflow.

EXCEPTION_CODE: (NTSTATUS) 0xc0000091 - {EXCEPTION}  Floating-point overflow.

EXCEPTION_PARAMETER1:  00000000

NTGLOBALFLAG:  2000000

APPLICATION_VERIFIER_FLAGS:  0

MANAGED_STACK: 
(TransitionMU)
0012E0F8 02657F5C IronPython!IronPython.Runtime.PythonContext.InitializeSystemState()+0xec
0012E108 026532E7 IronPython!IronPython.Runtime.PythonContext..ctor(Microsoft.Scripting.Runtime.ScriptDomainManager, System.Collections.Generic.IDictionary`2)+0x247
(TransitionUM)
(TransitionMU)
0012E60C 792EF7C0 mscorlib_ni!System.RuntimeMethodHandle.InvokeConstructor(System.Object[], System.SignatureStruct, System.RuntimeTypeHandle)+0x10
0012E640 792EF55A mscorlib_ni!System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+0xfa
0012E6D0 79288D96 mscorlib_ni!System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[])+0x3e6
0012E730 79280E10 mscorlib_ni!System.Activator.CreateInstance(System.Type, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[])+0x70
0012E754 02652BA1 Microsoft_Scripting!Microsoft.Scripting.Runtime.LanguageConfiguration.LoadLanguageContext(Microsoft.Scripting.Runtime.ScriptDomainManager, Boolean ByRef)+0x
LAST_CONTROL_TRANSFER:  from 790a40fa to 79098f48

PRIMARY_PROBLEM_CLASS:  WRONG_SYMBOLS

BUGCHECK_STR:  APPLICATION_FAULT_WRONG_SYMBOLS

STACK_TEXT:  
79098f45 mscorjit!Compiler::FlatFPIsSameAsFloat+0x7


FOLLOWUP_IP: 
mscorjit!Compiler::FlatFPIsSameAsFloat+7
79098f45 d95dfc          fstp    dword ptr [ebp-4]

SYMBOL_STACK_INDEX:  0

SYMBOL_NAME:  mscorjit!Compiler::FlatFPIsSameAsFloat+7

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: mscorjit

IMAGE_NAME:  mscorjit.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  492b8341

STACK_COMMAND:  dds 79098f45 ; kb

FAILURE_BUCKET_ID:  WRONG_SYMBOLS_c0000091_mscorjit.dll!Compiler::FlatFPIsSameAsFloat

BUCKET_ID:  APPLICATION_FAULT_WRONG_SYMBOLS_mscorjit!Compiler::FlatFPIsSameAsFloat+7

Followup: MachineOwner
---------

Floating-point overflow in Delphi when working with foreign .dlls? Ask uncle Google about it and after a while you find something like this. Or, as in my case, Dino sends you the direct link :-)

Another useful commands:

.loadby sos mscorwks
!clrstack -a
!DumpStackObjects
!dumpobj 07d996fc
.load C:\Program Files (x86)\Microsoft Silverlight\3.0.40818.0\sos.dll
.load C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll
.sympath SRV*c:\dos\DebugSymbols*http://msdl.microsoft.com/download/symbols

To recap it:

If you have a problem with your program, run it in WinDbg and !analyze -v it. WinDbg tells you a lot of useful information which you can utilize and find a solution for your problem.