3

Running a c# windows app, forced platform target of x86, on a 64 bit host.

When the app is compiled using "Optimize code" option get this error during execution.

First-chance exception at 0x74F7C41F (KernelBase.dll) in sldotnetsso.exe: 0x02345678 (parameters: 0x80000001).
First-chance exception at 0x74F7C41F in sldotnetsso.exe: Microsoft C++ exception: EEException at memory location 0x0847EC54.
First-chance exception at 0x74F7C41F in sldotnetsso.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74F7C41F in sldotnetsso.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
A first chance exception of type 'System.InvalidProgramException' occurred in slDotNetSSO.exe

The exception is raised when I try and step into getNativeWindowHandle.

somfunc() {
  m_id = CDescribeControl.getNativeWindowHandle(m_element);
}

class CDescribeControl{

    //NativeWindowHandle
    public static string getNativeWindowHandle(AutomationElement element)
    {
        string windowHandle = "";
        object classNameNoDefault = element.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty, true);
        if (classNameNoDefault == AutomationElement.NotSupported)
        {
            // property not supported
            // runtime ID as this is ment to be session unique
            classNameNoDefault = element.GetCurrentPropertyValue(AutomationElement.RuntimeIdProperty, true);
            if (classNameNoDefault == AutomationElement.NotSupported)
            {
                windowHandle = "0";
            }
            else
            {
                Int32[] arr = (Int32[])classNameNoDefault;//element.GetRuntimeId();
                foreach (int runidpart in arr)
                {
                    windowHandle += runidpart.ToString("X") + " ";
                }
            }
        }
        else
        {
            int res = (int)classNameNoDefault;//element.Current.NativeWindowHandle
            windowHandle = res.ToString("X");
        }

        return windowHandle;
    }

When the app is compiled without "Optimize code" it runs successfully. Would like to compile with "Optimize code".

Any ideas on the cause of the issue?

BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68
Greg Domjan
  • 13,943
  • 6
  • 43
  • 59
  • have you had a look at: http://support.microsoft.com/kb/312544 ? Also the question http://stackoverflow.com/questions/23563299/invalidprogramexception-common-language-runtime-detected-an-invalid-program looks similar, but was sadly unanswered. – BatteryBackupUnit Jun 18 '14 at 06:47
  • An idea: element.GetCurrentPropertyValue returns an enum or int value in this call. That's a "value type". But it gets assigned to an "object", i.e. a reference type. Not sure if that could cause trouble with "optimized code". – Bernhard Hiller Jun 18 '14 at 07:55
  • @BatteryBackupUnit Thanks for the KB link, I just wasn't searching on the right keyword as you picked in the title as well. – Greg Domjan Jun 18 '14 at 12:56
  • @BernhardHiller Thanks for the suggestion, the api/examples show returning object - http://msdn.microsoft.com/en-us/library/system.windows.automation.automationelement.nativewindowhandleproperty(v=vs.110).aspx for my reference when I forget. I might try a more direct conversion without the ignoreDefaultValue option just to see if there is some change. – Greg Domjan Jun 18 '14 at 13:04
  • In case you decide to analyse the issue further (using PEVerify as described in the kb), i would appreciate it if you would post your findings and how you proceeded. I think it's a rather complicated topic and there'll be quite a few users who'll be able to benefit from it in the future. – BatteryBackupUnit Jun 19 '14 at 05:30

0 Answers0