Causes of intermitant Arg_ArgumentException on in Production deployment? - silverlight

We have just recently deployed a Trusted, In-Browser, Silverlight 5 application to our Production webserver. We are getting fairly frequent ArgumentExceptions captured by the App.xaml.cs UnhandledException handler. So far we have been unable to determine the source of the exception.
We are not seeing the exception when running under the debugger (I have that explicitly enabled the exception for capture under Debug->Exceptions....). Some users see this error very frequently, while others never see the error. It doesn't seem to be a fatal error as the users can just click the OK button from the ErrorWindow that we display and everything functions normally.
To stop annoying the users, I have added a handler for ArgumentException types and just mark it as handled and continue on. However, I am still logging the errors and would really like to determine the actual source so that I can fix the problem. Just ignoring the exception doesn't seem like a long term solution.
The Stack trace is below and is the same for all ArgumentExceptions.
Any ideas on how I can troubleshoot better and determine the cause of this exception?
Thanks,
Tim
Unhandled Exception: [Arg_ArgumentException]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.10411.00&File=mscorlib.dll&Key=Arg_ArgumentException :
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, Double d)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.PerformTargetLoaded()
at System.Windows.Data.BindingExpression.TargetLoaded(Object o, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex

Related

XamlParseException: '' is not a valid value for property 'RuntimeVisibility'?

While editing a WPF custom control the design view in Visual Studio 2019 ran into this error:
(entire exception details down below).
Web searches have turned up nothing useful for RuntimeVisibility, although there are other similarly worded "is not a valid value" messages they seem quite varied. I can't even find the term "RuntimeVisibility" almost at all related to WPF.
So I tried to debug the VS2019 designer process by attaching to XDesProc in a separate VS2019 instance. By enabling trapping of all exceptions it would indeed break when the control in question was loaded into the designer. But it isn't failing in any user-level code; the problem emerges from somewhere deep inside the framework and the debugging information at that stack frame is meaningless to me.
I'm looking for a methodology or advice to track down the root cause of this problem. While it's annoying in the designer I'm more concerned if this could lead to an error at runtime. As noted, the mysterious RuntimeVisibility property doesn't seem like a designer-specific issue.
Full exception info:
XamlParseException: '' is not a valid value for property 'RuntimeVisibility'.
StackTrace
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
at System.Windows.FrameworkElement.ApplyTemplate()
InnerException: '' is not a valid value for property 'RuntimeVisibility'.
ArgumentException: '' is not a valid value for property 'RuntimeVisibility'.
StackTrace
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
InnerException: None
After I gave up on debugging XDesProc I resorted to commenting things in/out in the XAML just on a hunch to see if I could locate the problem. I didn't specifically know that it originated in the XAML but that turned out to be the case.
By working "outside-in" (meaning, comment out almost the entire body of the XAML, and then gradually add things back in) I was able to narrow it down to one line that, when removed, also eliminates the error:
<Canvas
ToolTipService.IsEnabled="{c:Binding ShowToolTip}"
Visibility="{c:Binding IsVisible}"
>
where c:Binding refers to:
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
(https://github.com/Alex141/CalcBinding)
When the Visibility attribute is removed, the error goes away.
What c:Binding is doing here is automatically converting between a bool property in the viewmodel and a proper Visibility value. This normally works fine, but I can just replace it with with a normal binding and a converter to work around the problem.

Windows Phone 8.1 app shows exception "Value does not fall within the expected range."

In first page I tap an image to view in large. This tapping event takes me to another second page. In this second page I zoom in or out the image. After that I press back key and come back to the first page. Then it throws this error message.
Value does not fall within the expected range.
System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
at System.Windows.UIElement.TransformToVisual(UIElement visual)
at Microsoft.Phone.Controls.GestureListener.GetInverseTransform(Boolean includeOffset, UIElement target)
at Microsoft.Phone.Controls.GestureListener.OnPinchCompleted(ManipulationDeltaEventArgs lastPinchInfo, Boolean gestureCompleted)
at Microsoft.Phone.Controls.GestureListener.OnManipulationDelta(Object sender, ManipulationDeltaEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
I am trying to find out the reason and solution of this problem but failed. I am looking for fruitfull answers to this question.

Frustrating error in WPF (.NET 4.0) internals: Hashtable insert failed. Load factor too high

I have built custom Rules Engine, where each element of this engine is a descendant of DependencyObject class, so that it could be described in XAML including support for dependency properties, markup extensions, bindings, and so on.
The purpose of this Rules Engine is to process certain information which comes as an input and to return the output information back to the queue.
The entire tree of object is being instantiated once (from XAML) in a single thread and the series of Input objects are being processed from the Input queue.
All works fine until I increase the number of threads - sometimes (not always!) it throws the following exception:
System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at MS.Internal.Data.ValueChangedEventManager.PrivateAddListener(Object source, IWeakEventListener listener, PropertyDescriptor pd)
at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
at MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
...
So I wonder, is this a bug in WPF internals or I have to take a closer look at my code? Has anyone experienced such problem before?
Since I don't use any global thread-unsafe objects that may interfere with each other, I expect DependencyObject to work correctly in multi-threaded environment, correct?
Try using a lock() statement around every write to make sure that your writes are not happening simultaneously.

Silverlight Application Error 0x17F8 on ComboBox_DropDownOpened

I have several similar comboboxes with custom templates that display one custom control on the dropdown. Suddenly one of those controls have broken and they give me the following error when I open the combobox.
Message: Unhandled Error in Silverlight 2 Application Error 0x17F8. Debugging resource strings are unavailable. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50401.0&File=mscorrc.dll&Key=0x17F8 at <INSERT_NAMESPACE>.ComboBox_DropDownOpened(Object sender, EventArgs e)
at System.Windows.Controls.ComboBox.OnDropDownOpened(EventArgs e)
at System.Windows.Controls.ComboBox.OnIsDropDownOpenChanged(Boolean isDropDownOpen)
at System.Windows.Controls.ComboBox.OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b)
at System.Windows.Controls.ComboBox.ElementDropDownToggle_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Primitives.ToggleButton.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
Line: 1
Char: 1
Code: 0
As you can see this only happens in deployed release versions and on the machines with no development environments. The same release version (and debug version) is working on my development machine.
I wrapped everything on the DropDownOpened event handler inside a try-catch-block to get more information but the catch doesn't fire at all.
I tried to Google the error but so far haven't found anything that would be helpful. Any advice how to start solving this? Could this be related to Silverlight runtime version or something that should be installed on the release machines as well?
I managed to solve the issue. I installed Developer Runtime to the machine for the hope that it would reveal better error message from the Exception. And it did! The issue was in the code of the control that was being displayed in the combobox dropdown. I fixed the bug and it's now working fine. Apparently even the strangest error message can mean the simplest thing :)
I wonder if there is a drawback on having the developer runtime instead of the standard runtime?

Exceptions are swallowed in my WPF application. How to force application to crash?

I am new to WPF, I am using VS2010 beta2, .NET 4.0.
Throw new Exception("test") in my code simply swallows exception and application does not crash.
This is not what I expect, I want the application to crash if unhandled exception occurs.
Is there a simple way to achieve this?
Also, neither Application.DispatcherUnhandledException nor AppDomain.UnhandledException is executed. It is probably because all code is executed as part of the data binding (I am using MVVM pattern and exception is thrown in ViewModel constructor).
While debugging I can look into Output window and find out what is wrong. But it seems to me odd, that application simply ignores error, leaves UI in incorrect state and does not crash.
Edit:
It seems that maybe only non-critical binding exceptions should occur while databinding. Maybe extracting functionality which is not directly related to binding (for example connecting to database) out of the binding execution can be the solution. However I am not sure how to achieve it in MVVM.
Simplified example:
XAML:
<DataTemplate DataType="{x:Type vm:ItemViewModel}">
<vw:ItemControl />
</DataTemplate>
<ContentControl
Content="{Binding Path=MyItem}"
/>
where MyItem creates and returns instance of ItemViewModel. Problem is that constructor of ItemViewModel is executed as part of the data binding and I am not sure if this is good practice (this constructor contains code which can fail - for example if database is not accessible).
You can catch the exceptions raised during binding and rethrow them - see the answer to this question.
The why's are answered here and here. They also explain ways to debug the exceptions better. No answers on how to turn them into unhandled exceptions though.
edit: You can instruct bindings to signal an error when a binding gets source updated. See here. Then you can use the ErrorTemplate (or use the default) to show the error in your UI.
{Binding Age, ValidatesOnDataErrors=true}
I will answer my question myself:
I achieved proper behavior by moving code which can fail (e.g. database access call) from (data bound) property getter to the constructor of View-Model. Additionaly I have used BackgroundWorker for this call, so code is executed asynchronously. I rethrow possible exception in RunWorkerCompleted - BackgroundWorker guarantees that it will be done on UI thread.
public TestViewModel()
{
BackgroundWorker bckgWorker = new BackgroundWorker();
bckgWorker.DoWork += ((s, e) => this.TestExecuteCode());
bckgWorker.RunWorkerCompleted += ((s, e) =>
{
if (e.Error != null)
throw e.Error;
});
bckgWorker.RunWorkerAsync();
}
private void TestExecuteCode()
{
this.DataBoundProperty = LoadDataFromDb();
}
I strongly prefer this approach of getting data asynchronously rather than IsAsync=true setting on Binding in XAML. This approach never swallows Exceptions compared to IsAsync approach when exceptions are thrown on render thread and are swallowed by default.
Warning: When running this code as part of unit tests, RunWorkerCompleted event handler will not be marshaled back to caller's thread by default. SynchronizationContext used by BackgroundWorker must be set manually in order to handle exceptions in unit tests correctly.
.Net 4.0\WPF introduces a way of doing this see answer here
I'm pretty sure a poorly designed application using .NET 4 could abuse AppDomain.FirstChanceException for this purpose.
The build log gives you everything you need to know for finding problems in your WPF application. Here's what was logged when I threw a NotImplementedException in some code I knew the UI was bound to:
System.Windows.Data Error: 17 : Cannot get 'ExitCommand' value (type 'RelayCommand') from '' (type 'ControlCenter'). BindingExpression:Path=ExitCommand; DataItem='ControlCenter' (Name='controlCenterWindow'); target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented.
at Tvl.Client.ControlCenter.get_ExitCommand() in C:\dev\Tvl\Client\ControlCenter.xaml.cs:line 25
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level)
at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'

Resources