How to Resolve Error "CS0739: 'type name' duplicate TypeForwardedToAttribute" in C#
The Compiler Error CS0739 is a redundancy error regarding Type Forwarding. The message reads: "'TypeName' duplicate TypeForwardedToAttribute."
Type Forwarding ([TypeForwardedTo]) allows you to move a class from one assembly to another without breaking compatibility. You leave a "signpost" in the old assembly pointing to the new location. However, just like you cannot define the same class twice, you cannot forward the same class twice. This error occurs if the assembly contains multiple TypeForwardedTo attributes pointing to the exact same type.
This guide explains how to identify and remove these duplicate directives.
Understanding Type Forwarding Uniqueness
When the Common Language Runtime (CLR) loads an assembly and sees a TypeForwardedTo attribute for MyClass, it records that MyClass is now located in the referenced assembly.
If it encounters a second attribute saying "And also, MyClass is located in the referenced assembly," it treats this as a conflict or a mistake. Even if both attributes point to the same destination, the duplication is invalid syntax.
Scenario: Duplicate Attributes
This often happens during refactoring or merging code. You might copy a block of attributes from one file to another, not realizing that the attribute was already defined elsewhere in the project (e.g., in AssemblyInfo.cs).
Example of error:
using System.Runtime.CompilerServices;
// Forwarding 'Widget' to another library
[assembly: TypeForwardedTo(typeof(Widget))]
using System.Runtime.CompilerServices;
// ⛔️ Error CS0739: Duplicate TypeForwardedToAttribute.
// You already forwarded 'Widget' in AssemblyInfo.cs.
[assembly: TypeForwardedTo(typeof(Widget))]
Solution: Remove the Duplicate
Search your entire solution for TypeForwardedTo(typeof(YourType)). You should find exactly one instance per type per assembly.
Solution: delete the extra attribute.
using System.Runtime.CompilerServices;
// ✅ Correct: Removed the duplicate line.
// [assembly: TypeForwardedTo(typeof(Widget))] <--- Deleted
Best Practice: Keep all your assembly-level attributes (like InternalsVisibleTo and TypeForwardedTo) in a single file (conventionally AssemblyInfo.cs or TypeForwards.cs) to avoid accidental duplication across multiple files.
Conclusion
CS0739 is a housekeeping error.
- Search: Use "Find in Files" (
Ctrl+Shift+F) to search for the specific type name mentioned in the error. - Consolidate: Ensure there is only one
[assembly: TypeForwardedTo(...)]line for that type in the project.