|
| 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 | + |
| 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 | + |
| 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 | +  |
| 42 | + |
| 43 | +  |
| 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%}) |
0 commit comments