11

I am getting this weird error when making a WP7 app, and I can not see why. The only output/ error message I get is "UnhandledException: The parameter is incorrect. : : : ProgramName.App"

This error occurs randomly, and I do not get any information from the debugger on how to resolve it. When I run the same code twice, one time it gets the error, and the other time it does not. So, have any of you got this error before, and can maybe tell me why it is happening? This is so frustrating, because it happens so randomly. Any proposals will be highly appreciated :)

EDIT: Here is the full stack trace:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value)
at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)
at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value)
at System.Windows.Controls.UIElementCollection.AddInternal(UIElement value)
at System.Windows.PresentationFrameworkCollection`1.Add(UIElement value)
at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 index, DependencyObject container, Boolean needPrepareContainer)
at System.Windows.Controls.ItemsControl.AddContainers()
at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.Pivot.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
kgrevehagen
  • 514
  • 6
  • 20

2 Answers2

6

I had the same problem. The fix for me was to give every element I would like to add a unique name (e.g. Name = Guid.NewGuid().ToString()). I hope this helps for you, too!

Jan K.
  • 2,542
  • 2
  • 21
  • 30
  • That was exactly the same thing I did, so it seems it works! Sorry for not posting that as an answer earlier. Didn´t seem like so many people had that problem. But great work, I´m marking this as an answer :) – kgrevehagen Dec 29 '11 at 08:35
  • What do you mean by "every element" ? Not sure I understand the answer :) – japf Sep 03 '12 at 08:08
  • With every element I mean each UI Control. Also each one you generate while runtime in your code. – Jan K. Oct 01 '12 at 11:05
  • @JanK. I decalre all element in XAML. So how can I add unique name like you mentioned ? – onmyway133 Nov 30 '12 at 06:55
  • @entropy Just remove the x:Name param – Poppyto Jan 26 '14 at 23:22
3

Click on Debug then Exceptions and then set Common Language Runtime Exceptions to "Thrown" and you should see the stack trace.

However, I do think it is a bug and can't tell how to go around it without looking at code/stacktrace

Adnan Bhatti
  • 3,410
  • 4
  • 25
  • 38
  • Thanks, that gave me the stack trace. It was an System.ArgumentException ("The parameter is incorrect") as expected, but how can I solve this? The stack trace is as follows: - at MS.Internal.XcpImports.CheckHResult(UInt32 hr) - at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value) - at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)............ Sorry for the bad formatting. – kgrevehagen Sep 14 '11 at 10:01
  • Add please the full stack trace to the question. Sometimes you get additional info this way. – Jan Slodicka Sep 14 '11 at 11:09
  • 1
    Hi Kgrevehagen, Please do us a favor and add complete stack trace in original question above by editing. Looking at these lines it doesn't tell anything. Is there anything more? Also please try stepping into the application by starting it in debug mode and using F11 keys to step into, that will give you good idea that at which point this exception is thrown. It could be some method who is trying to pass incorrect value or it also could be that application is taking more memory than available. This could be the case in the development of phone application. – Adnan Bhatti Sep 14 '11 at 14:36
  • I just need to get the exception again and remember to have set Common Language Runtime Exceptions to "Thrown"to get the full stacktrace. The thing i set to "Thrown" seems to be unset each time i open up Visual Studio. Weird.. – kgrevehagen Sep 16 '11 at 15:10
  • When you get the exception (having set the setting to break when an exception is thrown), double click on the second stack from (from the top), and view locals & autos in the debugger to get a sense of what the collection & value are... – Damian Sep 22 '11 at 16:56
  • When I look at locals & autos it doesn´t give me any useful information, and especially not where the problem might be. Is it in the xaml or the code?Could it be anything with the sizing of elements?I have kind of managed to reproduce it;when I put one particular user control in a pivotitem.But this usercontrol is only slightly different from another one that works.And this usercontrol works other places, at least sometimes. Could this be a race condition problem? Any help or just putting me in the right direction would be highly appreciated, as this error freezes the app several times. – kgrevehagen Sep 26 '11 at 17:09