Articles in this section
Category / Section

How to resolve ambiguous type reference exception in WPF DataGrid ?

3 mins read

Consider you are declaring control or class in xaml with same name present in two different dlls. And also consider both the dlls are reference to your project and declared using common namespace in xaml. In this case, you will get ambiguous type reference exception when running the application.

 

For example,

In the below code snippet GridCell style is declared and it is present in both Syncfusion.SfGrid.WPF dll and Syncfusion.Grid.WPF dll. Also GridCell referred from common namespace http://schemas.Syncfusion.com/wpf. If you have both Syncfusion.SfGrid.WPF and Syncfusion.Grid.WPF as reference, then when running application you will get ambiguous type reference exception.

XAML

<Window x:Class="SfDataGridDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SfDataGridDemo"
        xmlns:Syncfusion=”http://schemas.Syncfusion.com/wpf”>                               
<Window.Resources>
        <Style TargetType="Syncfusion:GridCell">
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="Foreground" Value="Red" />
        </Style>
</Window.Resources>
</Window>

 

It is because both Syncfusion.SfGrid.WPF and Syncfusion.Grid.WPF dlls are present in common namespace http://schemas.Syncfusion.com/wpf. Also GridCell control is present in both the dlls with same name, it leads to ambiguous type reference exception if you reference http://schemas.Syncfusion.com/wpf to your project.

Solution

You can overcome this problem by two ways,

Way 1: Based on the components used in your application you can add only required dlls. For example if you use SfDataGrid in your code, you don’t need to add Syncfusion.Grid.WPF or Syncfusion.GridCommon.WPF dll reference.

 

Way 2: If you are in need to refer both dlls in your project. Then you can declare the namespace for GridCell explicitly by specifying assembly as below,

xmlns:Syncfusion=”clr-namespace:Syncfusion.UI.Xaml.Grid;assembly=Syncfusion.SfGrid.WPF”

XAML

<Window x:Class="SfDataGridDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SfDataGridDemo"
        xmlns:Syncfusion=”clr-namespace:Syncfusion.UI.Xaml.Grid;
                                       assembly=Syncfusion.SfGrid.WPF”>                               
</Window>
<Window.Resources>
        <Style TargetType="Syncfusion:GridCell">
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="Foreground" Value="Red" />
        </Style>
</Window.Resources>

 


Conclusion

I hope you enjoyed learning about how to esolve ambiguous type reference exception in WPF DataGrid.

You can refer to our WPF DataGrid WPF DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied