Skip to content

Commit c7b3214

Browse files
Merge pull request #490 from telerik/new-kb-resolving-namespace-conflicts-043a16a246a141649f0e580dd3c2e190
Added new kb article resolving-namespace-conflicts
2 parents 060965e + 9cda731 commit c7b3214

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

getting-started/Installation/nuget-packages.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ The following list represents the available NuGet packages for the Document Proc
8282

8383
* [Restoring NuGet Packages in Your CI Workflow]({%slug using-nuget-keys%})
8484
* [How to Obtain Telerik Document Processing Libraries for .NET Framework, .NET Standard, .NET Core, .NET 6/.NET 8/.NET 9]({%slug distribute-telerik-document-processing-libraries-net-versions%})
85+
* [Resolving Namespace Conflicts in Telerik Document Processing Libraries]({%slug radspreadprocessing-resolving-namespace-conflicts%})
17.1 KB
Loading
26.4 KB
Loading
10.7 KB
Loading
25.6 KB
Loading
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Resolving Namespace Conflicts in Telerik Document Processing Libraries
3+
description: This article demonstrates how to resolve namespace conflicts when using Telerik Document Processing in a .NET Core project with both .NET Standard and .NET Framework packages/assemblies referenced.
4+
type: how-to
5+
page_title: How to Fix Namespace Conflicts in RadSpreadProcessing for Document Processing
6+
slug: radspreadprocessing-resolving-namespace-conflicts
7+
tags: spreadprocessing, document, processing, namespace, extern, alias, net, core, standard
8+
res_type: kb
9+
ticketid: 1673450
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| 2024.4.1106| Telerik Document Processing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
17+
18+
## Description
19+
20+
When working on a .NET Core project that utilizes both, the .NET Standard and .NET Framework version of a specific Document Processing library, e.g. `Telerik.Documents.Spreadsheet` and `Telerik.Windows.Documents.Spreadsheet` packages, a namespace conflict arises due to the `Workbook` class existing in both packages. This conflict results in a compiler error, preventing successful compilation.
21+
22+
![Installed Packages](images/installed-packages.png)
23+
24+
>note It is not recommended to install the .NET Standard and .NET Framework version of the Document Processing libraries simultaneously in the same project. Install the NuGet package which is compatible with the application's Target framework and Target OS.
25+
26+
![Conflicting Assemblies Error](images/conflicting-assemblies-error.png)
27+
28+
This knowledge base article also answers the following questions:
29+
- How can I resolve type conflicts in .NET Core projects using Telerik Document Processing libraries?
30+
- What is the correct way to handle namespace conflicts when using Telerik Document Processing in mixed .NET environments?
31+
- How do I use the C# extern alias feature to differentiate between similar types in different assemblies?
32+
33+
## Solution
34+
35+
Depending on the target framework of your project (NET Framework, .NET Standard .NET Core, .NET 6, etc.), you should install the library version accordingly. However, if you need to install both versions for any reason, to resolve the compile-time error caused by the conflicting `Workbook` type in both assemblies, utilize the C# [extern alias](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias) feature. This approach allows you to differentiate between assemblies and use types from both without conflict. Follow the steps below:
36+
37+
1. **Assign Alias to NuGet Packages**
38+
- For the `Telerik.Documents.Spreadsheet` NuGet package, set its alias to `StandardHelper` (or any preferred alias).
39+
- For the `Telerik.Windows.Documents.Spreadsheet` NuGet package, set its alias to `FrameworkHelper` (or any preferred alias).
40+
41+
![StandardHelper Alias](images/standardhelper-alias.png)
42+
43+
![FrameworkHelper Alias](images/frameworkhelper-alias.png)
44+
45+
2. **Use Extern Alias in Your Code**
46+
- At the top of your source file where you intend to use the conflicting types, add the `extern alias` directive for each alias you assigned. This directive differentiates the assemblies, allowing you to reference each type explicitly.
47+
48+
```csharp
49+
extern alias StandardHelper;
50+
//extern alias FrameworkHelper;
51+
52+
using StandardHelper::Telerik.Windows.Documents.Spreadsheet.Model;
53+
//using FrameworkHelper::Telerik.Windows.Documents.Spreadsheet.Model;
54+
55+
namespace YourNamespace
56+
{
57+
internal class Program
58+
{
59+
static void Main(string[] args)
60+
{
61+
Workbook workbook;
62+
}
63+
}
64+
}
65+
```
66+
67+
By following these steps, you can successfully resolve the namespace conflict and use the `Workbook` class from the desired NuGet package in your .NET Core project.
68+
69+
## See Also
70+
71+
- [Installation: NuGet Packages for Document Processing]({%slug installation-deploying-telerik-document-processing%})
72+
- [C# Language Reference: extern alias](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias)
73+
- [What Versions of Document Processing Libraries are Distributed with the Telerik Products]({%slug distribute-telerik-document-processing-libraries-net-versions%})

troubleshooting/telerik-nuget.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ Another common problem is that your machine (PC, GitHub Actions runner or Azure
9999

100100
* https://nuget.telerik.com/nuget/Search()?$filter=IsAbsoluteLatestVersion&searchTerm=%27WPF%27&includePrerelease=true&$skip=0&$top=100&semVerLevel=2.0.0.
101101

102-
After you enter your telerik.com username and password, you should see an XML search result containing a list of all the Telerik.UI.for.WPF packages available with your license.
102+
After you enter your telerik.com username and password, you should see an XML search result containing a list of all the Telerik.UI.for.WPF packages available with your license.
103+
104+
## See Also
105+
106+
* [Resolving Namespace Conflicts in Telerik Document Processing Libraries]({%slug radspreadprocessing-resolving-namespace-conflicts%})

0 commit comments

Comments
 (0)