none
Argument Out Of Range Exception parameter: paragraphWidth

    Question

  • I am developing an add-in for Microsoft Project 2010 using VSTO 2010.  I have a custom task pane that has a button, whose sole purpose is to open a WPF window.  My solution targets .Net 4.0. 

    In the Window I have the following XAML:

    <StackPanel Orientation="Horizontal">
    <TextBlock>Text Block 1</TextBlock> 
    <TextBlock>Text Block 2</TextBlock>
    </StackPanel>

    In certain environments, specifically environments with 32 bit office and 64 bit Windows 7, this source code throws the following exception:

     ArgumentOutOfRangeException param name: ParagraphWidth

    If I change the orientation to vertical on the stack panel then I do not get the exception. I can also reproduce this exception using a combobox and/or a listview control. 

    I have the following stack trace:

       at MS.Internal.TextFormatting.TextFormatterImp.VerifyTextFormattingArguments(TextSource textSource, Int32 firstCharIndex, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextRunCache textRunCache)
       at MS.Internal.TextFormatting.TextFormatterImp.PrepareFormatSettings(TextSource textSource, Int32 firstCharIndex, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache, Boolean useOptimalBreak, Boolean isSingleLineFormatting, TextFormattingMode textFormattingMode)
       at MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(TextSource textSource, Int32 firstCharIndex, Int32 lineLength, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache)
       at MS.Internal.TextFormatting.TextFormatterImp.FormatLine(TextSource textSource, Int32 firstCharIndex, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache)
       at System.Windows.Controls.TextBlock.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.StackPanel.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Border.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Window.MeasureOverrideHelper(Size constraint)
       at System.Windows.Window.MeasureOverride(Size availableSize)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Interop.HwndSource.SetLayoutSize()
       at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
       at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
       at System.Windows.Window.SetRootVisual()
       at System.Windows.Window.SetRootVisualAndUpdateSTC()
       at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
       at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
       at System.Windows.Window.CreateSourceWindowDuringShow()
       at System.Windows.Window.SafeCreateWindowDuringShow()
       at System.Windows.Window.ShowHelper(Object booleanBox)
       at System.Windows.Window.Show()
       at System.Windows.Window.ShowDialog()
       at WPFUI.WPFUserControl.Button_Click(Object sender, RoutedEventArgs e) in C:\test\TestArgumentOutOfRangeException\WPFUI\WPFUserControl.xaml.cs:line 30
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       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

    I have an example solution that can be downloaded here:

    www.smarterpm.com/TestArgumentOutOfRangeException.zip

    The above solution requires Microsoft Project 2010 to run correctly.  I have been able to successfully recreate this error on machines that have 32 bit office and 64 bit Windows. But I have also been able to reproduce this on a virtual machine that has 32 bit office and 32 bit windows XP installed.

    Any help on this would be very much appreciated, thanks in advance.

    • Moved by Annabella Luo Tuesday, May 01, 2012 3:55 AM (From:Windows Presentation Foundation (WPF))
    Tuesday, April 24, 2012 8:42 PM

Answers

  • This problem is fixed in the .net framework 4.5, but for those of you still using 4.0  there is a work around available.  The floating point precision is being changed by the Microsoft Project, so you have to set it back using the following code: 

    [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int _controlfp(int newControl, int mask);
    
    const int _RC_NEAR = 0x00000000;
    const int _PC_53 = 0x00010000;
    const int _EM_INVALID = 0x00000010;
    const int _EM_UNDERFLOW = 0x00000002;
    const int _EM_ZERODIVIDE = 0x00000008;
    const int _EM_OVERFLOW = 0x00000004;
    const int _EM_INEXACT = 0x00000001;
    const int _EM_DENORMAL = 0x00080000;
    const int _CW_DEFAULT = (_RC_NEAR + _PC_53 +
                                     _EM_INVALID + _EM_ZERODIVIDE +
                                     _EM_OVERFLOW + _EM_UNDERFLOW +
                                     _EM_INEXACT + _EM_DENORMAL);
     
     
    
            private void ThisAddIn_Startup(object sender,    System.EventArgs e)
            {
                int value = _controlfp(_CW_DEFAULT, 0xfffff);
              
                
            }

    • Marked as answer by Thomas_Bell Thursday, October 11, 2012 4:13 PM
    Thursday, October 11, 2012 4:13 PM

All replies

  • Hi Thomas_Bell,

    According to your description, I understand you use VSTO 2010 show a WPF Window and get a exception.

    I'm not familiar with VSTO2010, but if you want to get a Horizontal layout panel, you can use WrapPanel in WPF to instead Stackpanel to try if it worked for you.

    Please let me know the result of your troubleshooting at your conveience.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    Friday, April 27, 2012 10:10 AM
  • Annabella,

    Thank you for your response.  Your answer is an interesting work around, but I am interested in a more comprehensive solution or at least comprehension of what the problem is.  The above exception can be reproduced not just with a stack panel but also a combo box, and a list view.  Is this a known issue?  I have done some research and it appears that this problem might be related to this post here: 

    http://social.msdn.microsoft.com/Forums/en/wpf/thread/9671a382-469c-4fb8-a781-d10235fb6589

    This post suggests the FPU precision is being changed somewhere in the Application, the problem is I do not know where that would be changed.  I have an example application that reproduces this issue. It can be found at the following address:

    www.smarterpm.com/TestArgumentOutOfRangeException.zip

     

    Monday, April 30, 2012 8:25 PM
  • Hi Thomas,

    I'm sorry I can't help you more due to your create a apps in VSTO, not WPF apps.

    I'm moving your thread to General Office forum, so that you can get a better help.

    Thank you for your understanding and support.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 01, 2012 3:53 AM
  • Hi Thomas,

    Did you add System.Xaml Namespace to your project?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 03, 2012 8:15 AM
    Moderator
  • Tom,

    Yes I did add that reference. You can see the example by downloading the link above.

    Thanks,

    Thomas

    Friday, May 04, 2012 12:43 PM
  • I have opened a support case with Microsoft regarding this issue.  It has been identified as a bug caused by Microsoft Project 2010 changing the floating point precision and causing an argument out of range exception inside the WPF framework.   As of now there is not a fix, I am currently in the process of working with the tech support team to determine whether this should be a hotfix. 

    I will update this thread as soon as I have any more information regarding a potential fix or workaround.

    Thomas


    • Edited by Thomas_Bell Thursday, May 10, 2012 11:15 PM
    Thursday, May 10, 2012 6:02 PM
  • Are there any updates to this issue?

    I'm having the same problem.

    Tuesday, May 22, 2012 10:28 AM
  • Same here,

    anything new on this case?

    Roy


    Royg

    Sunday, September 02, 2012 8:25 AM
  • I got the same problem. Any news?

    Regards B.

    Tuesday, September 25, 2012 9:04 AM
  • This problem is fixed in the .net framework 4.5, but for those of you still using 4.0  there is a work around available.  The floating point precision is being changed by the Microsoft Project, so you have to set it back using the following code: 

    [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int _controlfp(int newControl, int mask);
    
    const int _RC_NEAR = 0x00000000;
    const int _PC_53 = 0x00010000;
    const int _EM_INVALID = 0x00000010;
    const int _EM_UNDERFLOW = 0x00000002;
    const int _EM_ZERODIVIDE = 0x00000008;
    const int _EM_OVERFLOW = 0x00000004;
    const int _EM_INEXACT = 0x00000001;
    const int _EM_DENORMAL = 0x00080000;
    const int _CW_DEFAULT = (_RC_NEAR + _PC_53 +
                                     _EM_INVALID + _EM_ZERODIVIDE +
                                     _EM_OVERFLOW + _EM_UNDERFLOW +
                                     _EM_INEXACT + _EM_DENORMAL);
     
     
    
            private void ThisAddIn_Startup(object sender,    System.EventArgs e)
            {
                int value = _controlfp(_CW_DEFAULT, 0xfffff);
              
                
            }

    • Marked as answer by Thomas_Bell Thursday, October 11, 2012 4:13 PM
    Thursday, October 11, 2012 4:13 PM