|
| 1 | +--- |
| 2 | +title: Resolving Ambiguous references |
| 3 | +description: This article describes how to resolve ambiguous references due to cross-platform project references. |
| 4 | +type: how-to |
| 5 | +page_title: How to Resolve Ambiguous References |
| 6 | +slug: dpl-resolve |
| 7 | +tags: spreadprocessing, document, processing, wpf, ambiguous, reference, extern, alias |
| 8 | +res_type: kb |
| 9 | +ticketid: 1684241 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| ---- | ---- | ---- | |
| 16 | +| 2025.1.205| RadSpreadProcessing|[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +When developing a WPF application that utilizes [RadSpreadProcessing]({%slug radspreadprocessing-overview%}) to set a font in a spreadsheet (referencing `Telerik.Windows.Documents.Core`), and the solution includes a cross-platform project referencing `Telerik.Documents.Core`, an ambiguous reference error may occur. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +The issue arises due to identical namespaces in both assemblies when both platform-specific projects and cross-platform projects are part of the solution. |
| 25 | + |
| 26 | +>note This is just an example scenario for WPF combined with SpreadProcessing. Usually, such ambiguity can happen regardless of the project type or library, as long as the project is cross-platform and there is a reference to the .NET Standard and .NET Framework version of the same DPL assembly. |
| 27 | +
|
| 28 | +## Solution |
| 29 | + |
| 30 | +The Telerik Document Processing libraries are available in .NET Framework, .NET 8/.NET 9 (or newer) for Windows and .NET Standard compatible versions. All versions are available as NuGet packages. The assemblies/packages for .NET Standard do not contain the word *Windows* in their name. Learn [What Versions of Document Processing Libraries are Distributed with the Telerik Products]({%slug distribute-telerik-document-processing-libraries-net-versions%}). |
| 31 | + |
| 32 | +In a WPF project, you need to use the assemblies containing the word *Windows* and avoid mixing .NET Framework and .NET Standard compatible versions. |
| 33 | + |
| 34 | +However, to resolve the ambiguous reference error in a WPF application using RadSpreadProcessing alongside a cross-platform project, use the [extern alias](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias) directive. This approach allows differentiating between assemblies that have the same namespace but are intended for different platforms. Follow the steps below to apply this solution: |
| 35 | + |
| 36 | +1. **Assign an alias to the conflicting assembly in the WPF project**. Right-click on the referenced assembly in the Solution Explorer and select `Properties`. In the `Aliases` field, enter a unique alias (e.g., `NetFramework`). |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +2. **Use the `extern alias` directive in your WPF project code**. At the top of your C# file where you are facing the ambiguous reference, declare the alias defined in step 1. This explicitly specifies which assembly to use for the conflicting types. |
| 41 | + |
| 42 | +```csharp |
| 43 | +extern alias NetFramework; |
| 44 | +using NetFramework::Telerik.Documents.Common.Model; |
| 45 | +``` |
| 46 | + |
| 47 | +3. **Reference the `ThemableFontFamily` using the alias**. After specifying the extern alias, use it to qualify the namespace of the `ThemableFontFamily` class or any other ambiguous type. This disambiguates the reference and allows your code to compile successfully. |
| 48 | + |
| 49 | +```csharp |
| 50 | +namespace YourNamespace |
| 51 | +{ |
| 52 | + public class YourClass |
| 53 | + { |
| 54 | + public void YourMethod() |
| 55 | + { |
| 56 | + // Use the ThemableFontFamily from the aliased assembly |
| 57 | + ThemableFontFamily fontFamily = new ThemableFontFamily("Courier New"); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +By following these steps, you can successfully resolve the ambiguous reference error and set the spreadsheet font in a WPF application using RadSpreadProcessing, even when your solution includes cross-platform projects. |
| 64 | + |
| 65 | +## See Also |
| 66 | + |
| 67 | +- [What Versions of Document Processing Libraries are Distributed with the Telerik Products]({%slug distribute-telerik-document-processing-libraries-net-versions%}) |
| 68 | +- [Resolve Compile-Time Error Between RadPdfProcessing and Telerik Reporting]({%slug resolve-compile-time-error-radpdfprocessing-telerik-reporting%}) |
| 69 | +- [C# Extern Alias - Microsoft Documentation](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias) |
0 commit comments