This is a migrated thread and some comments may be shown as answers.

AmbiguousMatchException When Rendering A Grid

11 Answers 407 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 09 May 2013, 06:00 PM

I am setting GridViewDataControl.ItemsSource to an instance of a QueryableCollectionView. When the grid is rendered on the screen I get an AmbiguousMatchException. Any ideas what might cause this?

I have included the stack trace below:

System.Reflection.AmbiguousMatchException was unhandled by user code

  HResult=-2147475171

  Message=Ambiguous match found.

  Source=mscorlib

  StackTrace:

       at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)

       at System.Type.GetProperty(String name)

       at Telerik.Windows.Controls.GridViewBoundColumnBase.GetValidationErrors(Object dataItem, String propertyName) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Columns\GridViewBoundColumnBase.cs:line 1694

       at Telerik.Windows.Controls.GridView.GridViewCell.<GetDataErrors>d__7.MoveNext() in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 704

       at Telerik.Windows.Data.EnumerableExtensions.Count(IEnumerable source) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Core\Data\Collections\EnumerableExtensions.cs:line 126

       at Telerik.Windows.Controls.GridView.GridViewCell.UpdateIsValidState() in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 624

       at Telerik.Windows.Controls.GridView.GridViewCell.UpdateValue() in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 1708

       at Telerik.Windows.Controls.GridView.GridViewCell.SetCellElement() in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 537

       at Telerik.Windows.Controls.GridView.GridViewRow.PrepareCell(GridViewCellBase cellBase, GridViewColumn column) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 915

       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.PrepareCell(GridViewCellBase cell, GridViewColumn column) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewCellsPanel.cs:line 403

       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.GetVirtualizedCell(GridViewColumn column, Boolean createIfNull) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewCellsPanel.Virtualization.cs:line 365

       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.RealizeAndMeasureCells(Int32 startIndex, Int32 predictedLastIndex, Func`2 calculateNextIndex) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewCellsPanel.Virtualization.cs:line 300

       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.UpdateVirtualizedCells() in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewCellsPanel.Virtualization.cs:line 235

       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.MeasureOverride(Size availableSize) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewCellsPanel.cs:line 290

       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.ItemsPresenter.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 System.Windows.Controls.Control.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.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.Controls.Control.MeasureOverride(Size constraint)

       at Telerik.Windows.Controls.GridView.GridViewRowItem.MeasureOverride(Size availableSize) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Rows\GridViewRowItem.cs:line 199

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.MeasureChild(UIElement child, Size layoutSlotSize, Int32 i) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewVirtualizingPanel.NestedLayoutStrategy.cs:line 1575

       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.MeasureOverride(Size constraint) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewVirtualizingPanel.NestedLayoutStrategy.cs:line 213

       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\Virtualization\GridViewVirtualizingPanel.cs:line 342

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.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.Controls.Control.MeasureOverride(Size constraint)

       at Telerik.Windows.Controls.GridView.GridViewDataControl.MeasureOverride(Size availableSize) in c:\TB\221\WPF_Scrum\Current_HotFix\Sources\Controls\GridView\GridView\GridView\GridViewDataControl.cs:line 6659

       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.Controls.StackPanel.StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)

       at System.Windows.Controls.StackPanel.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.ItemsPresenter.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.Controls.Control.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Control.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.Controls.Border.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.ContextLayoutManager.UpdateLayout()

       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

       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)

  InnerException: 

11 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 09 May 2013, 06:06 PM
Hello Albert,

We used to have such issue before, but it has already been resolved. Could you clarify which version you are working with?  

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Albert
Top achievements
Rank 1
answered on 09 May 2013, 06:16 PM
Hi Maya,

I am using version 2013.1.0422.45.

Kind Regards,
Albert
0
Albert
Top achievements
Rank 1
answered on 09 May 2013, 09:48 PM
Maya, what issue in the past caused this issue?

Kind Regards,
Albert
0
Maya
Telerik team
answered on 10 May 2013, 06:16 PM
Hi Albert,

Tha StackTrace of the issue we had was exactly the same and was reproducible only when there are more than one DataAnnotations attributes added. Is that your case or is there something more specific ? 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Albert
Top achievements
Rank 1
answered on 17 May 2013, 09:06 PM
This appears to be a bug with the RadGridView. It occurs when you have a column named "Item".

Is there a work-around or fix available?

Kind Regards,
Albert
0
Albert
Top achievements
Rank 1
answered on 17 May 2013, 09:11 PM
I have a simple project that demonstrates the problem, but I am not able to access Telerik's Support Ticketing System as it is down at the moment... Here are some code snippets:

MainWindow.xaml:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"

        x:Class="ItemColumnBug.MainWindow"
        Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Content="PopulateWithItemColumn" Click="PopulateWithItemColumn_Click" />
<Button Grid.Row="1" Content="PopulateWithItemXXXColumn" Click="PopulateWithItemXXXColumn_Click" />
<telerik:RadGridView x:Name="RadGridView" Grid.Row="2"/>
</Grid>
</Window>


MainWindow.xaml.cs:

using System.Data;
using System.Linq;
using System.Windows;
using Telerik.Windows.Data;

namespace ItemColumnBug
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void PopulateWithItemColumn_Click(object sender, RoutedEventArgs e)
{
LoadGrid("Item");
}

private void PopulateWithItemXXXColumn_Click(object sender, RoutedEventArgs e)
{
LoadGrid("ItemXXX");
}

private void LoadGrid(string columnName)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn(columnName, typeof(string)));

DataRow newRow = dt.NewRow();
newRow[columnName] = "hello";
dt.Rows.Add((newRow));

newRow = dt.NewRow();
newRow[columnName] = "there";
dt.Rows.Add((newRow));

RadGridView.ItemsSource = dt;
}
}
}


0
Maya
Telerik team
answered on 20 May 2013, 05:56 PM
Hello Albert,

Indeed, you are right - there is such an exception being thrown when you bind to a property named "Item". The thing is that the DataRow object has properties with name "Item" and when we try to invoke the GetProperty() method, it throws the exception. You can prove that with the following code:

DataTable dt = new DataTable();
          DataRow newRow = dt.NewRow();
          var hasItemProperty = newRow.GetType().GetProperties().Any(p => p.Name == "Item");
          var itemProperties = newRow.GetType().GetProperties().Where(p => p.Name == "Item");
          var count = itemProperties.Count();

The count of the items will be 6 in this case.
Nevertheless, I will handle the exception internally so that it is not thrown directly in release mode. Still, my recommendation would be to name your properties so that there is no confustion with default ones - like Item, Column, DataRow for example.
Anyway, thank you for the information and cooperation. I have updated your telerik points accordingly. Let me know if you have any further problems.

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Albert
Top achievements
Rank 1
answered on 20 May 2013, 06:45 PM
Thanks for the reply, Maya. When will the next release that includes the fix be?

Kind Regards,
Albert
0
Maya
Telerik team
answered on 20 May 2013, 10:24 PM
Hi Albert,

The fix will be incuded in our next internal build coming on Monday as well as in our official release - Q2 2013.

 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Adige S.p.A
Top achievements
Rank 1
answered on 05 Dec 2013, 02:18 PM
I have the same problem with the RadPropertyGrid of WPF Q3 2013, I'm trying to do a binding to a "Value" property of my object


           propDef = new PropertyDefinition()
                    {
                        DisplayName = arg.Name.Value,
                        Description = arg.Description.Value,
                        Binding = new Binding()
                        {
                            Source = arg,
                            Path = new PropertyPath("Value", null) 
                           
                        },
                       
                        EditorTemplate = this.argTemplateSelector.SelectTemplate(arg, this.PropertyGrid)
                    }

but when the PropertyGrid is rendered on the screen I get an AmbiguousMatchException.
0
Dimitrina
Telerik team
answered on 06 Dec 2013, 08:34 AM
Hi,

Your question is not related to RadGridView, so I would suggest you to post such questions in the respective forum category.

As to your particular case, have you referenced assemblies built against .NET Framework 4.0 or against .NET Framework 4.5? Would it also be possible for you to send us a sample project demonstrating the issue?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Albert
Top achievements
Rank 1
Answers by
Maya
Telerik team
Albert
Top achievements
Rank 1
Adige S.p.A
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or