Resolving Ambiguous references
Environment
Version | Product | Author |
---|---|---|
2025.1.205 | RadSpreadProcessing | Desislava Yordanova |
Description
When developing a WPF application that utilizes RadSpreadProcessing 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.
The issue arises due to identical namespaces in both assemblies when both platform-specific projects and cross-platform projects are part of the solution.
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.
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 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:
-
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 theAliases
field, enter a unique alias (e.g.,NetFramework
).
-
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.
extern alias NetFramework;
using NetFramework::Telerik.Documents.Common.Model;
-
Reference the
ThemableFontFamily
using the alias. After specifying the extern alias, use it to qualify the namespace of theThemableFontFamily
class or any other ambiguous type. This disambiguates the reference and allows your code to compile successfully.
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.