Skip to content

Added new kb article dpl-resolve-ambiguous-references #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions knowledge-base/dpl-resolve-ambiguous-references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: Resolving Ambiguous references
description: This article describes how to resolve ambiguous references due to cross-platform project references.
type: how-to
page_title: How to Resolve Ambiguous References
slug: dpl-resolve
tags: spreadprocessing, document, processing, wpf, ambiguous, reference, extern, alias
res_type: kb
ticketid: 1684241
---

## Environment

| Version | Product | Author |
| ---- | ---- | ---- |
| 2025.1.205| RadSpreadProcessing|[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|

## Description

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.

![Ambiguous Error](images/ambiguous_error.png)

The issue arises due to identical namespaces in both assemblies when both platform-specific projects and cross-platform projects are part of the solution.

>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.

## Solution

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%}).

In a WPF project, you need to use the assemblies containing the word *Windows* and avoid mixing .NET Framework and .NET Standard compatible versions.

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:

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`).

![NET Framework Aliases](images/framework_aliases.png)

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.

```csharp
extern alias NetFramework;
using NetFramework::Telerik.Documents.Common.Model;
```

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.

```csharp
namespace YourNamespace
{
public class YourClass
{
public void YourMethod()
{
// Use the ThemableFontFamily from the aliased assembly
ThemableFontFamily fontFamily = new ThemableFontFamily("Courier New");
}
}
}
```

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.

## See Also

- [What Versions of Document Processing Libraries are Distributed with the Telerik Products]({%slug distribute-telerik-document-processing-libraries-net-versions%})
- [Resolve Compile-Time Error Between RadPdfProcessing and Telerik Reporting]({%slug resolve-compile-time-error-radpdfprocessing-telerik-reporting%})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference kb in another article

- [C# Extern Alias - Microsoft Documentation](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias)
Binary file added knowledge-base/images/ambiguous_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added knowledge-base/images/framework_aliases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.