Kaganar
Kaganar

Reputation: 6570

Set property 'System.Windows.FrameworkElement.Height' threw an exception

An in-house application coded in C# and WPF works without incident for 20+ people except one user. The first window displayed usually (but not always) results in an exception that our exception handler diligently reports:

Exception trace:
Set property 'System.Windows.FrameworkElement.Height' threw an exception.
Overflow or underflow in the arithmetic operation.

Stack trace:
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

There's no obvious problem with the XAML, and I'm never directly touching the height of any element. I've tried making the window default to a larger or smaller size, but that hasn't resolved anything. It's actually a simple user log in window. The problem often but not always goes away after goes away on reboot.

I don't expect a silver bullet to this problem, but it's not clear where I should begin in debugging -- WPF seems to have a design flaw that makes it nearly impossible to debug such exceptions?

Upvotes: 3

Views: 2630

Answers (1)

Kaganar
Kaganar

Reputation: 6570

After searching again as Abbas suggested, this is the solution I ended up with:

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    [DllImport("msvcr71.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int _controlfp(int n, int mask);

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        _controlfp(0x9001F, 0xFFFFF);

        // ... whatever else you want to do on application startup
        // e.g. add last-resort error handler via DispatcherUnhandledException
    }
}

Some software apparently can leave floating point calculation modes in an unexpected state. The _controlfp call sets it back to the expected mode.

Upvotes: 4

Related Questions