-
Notifications
You must be signed in to change notification settings - Fork 41
Added new kb article resolving-namespace-conflicts #490
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
dessyordanova
merged 3 commits into
master
from
new-kb-resolving-namespace-conflicts-043a16a246a141649f0e580dd3c2e190
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| title: Resolving Namespace Conflicts in Telerik Document Processing Libraries | ||
| 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. | ||
| type: how-to | ||
| page_title: How to Fix Namespace Conflicts in RadSpreadProcessing for Document Processing | ||
| slug: radspreadprocessing-resolving-namespace-conflicts | ||
| tags: spreadprocessing, document, processing, namespace, extern, alias, net, core, standard | ||
| res_type: kb | ||
| ticketid: 1673450 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| | Version | Product | Author | | ||
| | --- | --- | ---- | | ||
| | 2024.4.1106| Telerik Document Processing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| | ||
|
|
||
| ## Description | ||
|
|
||
| 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. | ||
|
|
||
|  | ||
|
|
||
| >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. | ||
|
|
||
|  | ||
|
|
||
| This knowledge base article also answers the following questions: | ||
| - How can I resolve type conflicts in .NET Core projects using Telerik Document Processing libraries? | ||
| - What is the correct way to handle namespace conflicts when using Telerik Document Processing in mixed .NET environments? | ||
| - How do I use the C# extern alias feature to differentiate between similar types in different assemblies? | ||
|
|
||
| ## Solution | ||
|
|
||
| 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: | ||
|
|
||
| 1. **Assign Alias to NuGet Packages** | ||
| - For the `Telerik.Documents.Spreadsheet` NuGet package, set its alias to `StandardHelper` (or any preferred alias). | ||
| - For the `Telerik.Windows.Documents.Spreadsheet` NuGet package, set its alias to `FrameworkHelper` (or any preferred alias). | ||
|
|
||
|  | ||
|
|
||
|  | ||
|
|
||
| 2. **Use Extern Alias in Your Code** | ||
| - 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. | ||
|
|
||
| ```csharp | ||
| extern alias StandardHelper; | ||
| //extern alias FrameworkHelper; | ||
|
|
||
| using StandardHelper::Telerik.Windows.Documents.Spreadsheet.Model; | ||
| //using FrameworkHelper::Telerik.Windows.Documents.Spreadsheet.Model; | ||
|
|
||
| namespace YourNamespace | ||
| { | ||
| internal class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| Workbook workbook; | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Installation: NuGet Packages for Document Processing]({%slug installation-deploying-telerik-document-processing%}) | ||
| - [C# Language Reference: extern alias](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias) | ||
| - [What Versions of Document Processing Libraries are Distributed with the Telerik Products]({%slug distribute-telerik-document-processing-libraries-net-versions%}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.