|
| 1 | +--- |
| 2 | +title: Resolving Namespace Conflicts in RadSpreadProcessing for Document Processing |
| 3 | +description: This article demonstrates how to resolve namespace conflicts when using RadSpreadProcessing in a .NET Core project with both .NET Standard and .NET Framework versions installed. |
| 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: radspreadprocessing, document processing, namespace, extern alias, .net core, .net standard |
| 8 | +res_type: kb |
| 9 | +ticketid: 1673450 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | +<tbody> |
| 16 | +<tr> |
| 17 | +<td>Product</td> |
| 18 | +<td>RadSpreadProcessing for Document Processing</td> |
| 19 | +</tr> |
| 20 | +</tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +When working on a .NET Core project that utilizes both `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. |
| 26 | + |
| 27 | +This knowledge base article also answers the following questions: |
| 28 | +- How can I resolve type conflicts in .NET Core projects using Telerik Document Processing libraries? |
| 29 | +- What is the correct way to handle namespace conflicts when using Telerik Document Processing in mixed .NET environments? |
| 30 | +- How do I use the C# extern alias feature to differentiate between similar types in different assemblies? |
| 31 | + |
| 32 | +## Solution |
| 33 | + |
| 34 | +To resolve the compile-time error caused by the conflicting `Workbook` type in both assemblies, utilize the C# `extern alias` feature. This approach allows you to differentiate between assemblies and use types from both without conflict. Follow the steps below: |
| 35 | + |
| 36 | +1. **Assign Alias to NuGet Packages** |
| 37 | + - For the `Telerik.Documents.Spreadsheet` NuGet package, set its alias to `StandardHelper` (or any preferred alias). |
| 38 | + - For the `Telerik.Windows.Documents.Spreadsheet` NuGet package, set its alias to `FrameworkHelper` (or any preferred alias). |
| 39 | + |
| 40 | +2. **Use Extern Alias in Your Code** |
| 41 | + - 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. |
| 42 | + |
| 43 | +```csharp |
| 44 | +extern alias StandardHelper; |
| 45 | +//extern alias FrameworkHelper; |
| 46 | +
|
| 47 | +using StandardHelper::Telerik.Windows.Documents.Spreadsheet.Model; |
| 48 | +//using FrameworkHelper::Telerik.Windows.Documents.Spreadsheet.Model; |
| 49 | +
|
| 50 | +namespace YourNamespace |
| 51 | +{ |
| 52 | + internal class Program |
| 53 | + { |
| 54 | + static void Main(string[] args) |
| 55 | + { |
| 56 | + Workbook workbook; |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +By following these steps, you can successfully resolve the namespace conflict and use the `Workbook` class from both Telerik Document Processing libraries in your .NET Core project. |
| 63 | + |
| 64 | +## See Also |
| 65 | + |
| 66 | +- [Installation: NuGet Packages for Document Processing](https://docs.telerik.com/devtools/document-processing/getting-started/installation/nuget-packages) |
| 67 | +- [C# Language Reference: extern alias](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias) |
| 68 | +- [What Versions of Document Processing Libraries are Distributed with the Telerik Products](https://docs.telerik.com/devtools/document-processing/knowledge-base/distribute-telerik-document-processing-libraries-net-versions) |
0 commit comments