Skip to content

How to Resolve Error "CS0739: 'type name' duplicate TypeForwardedToAttribute" in C#

Learn how to fix the C# compiler error CS0739 caused by duplicate TypeForwardedTo attributes in your assembly, including identification and cleanup steps.

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:

AssemblyInfo.cscsharp
using System.Runtime.CompilerServices;

// Forwarding 'Widget' to another library
[assembly: TypeForwardedTo(typeof(Widget))]
TypeForwards.cs (Another file in the same project)csharp
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.

TypeForwards.cscsharp
using System.Runtime.CompilerServices;

// ✅ Correct: Removed the duplicate line.
// [assembly: TypeForwardedTo(typeof(Widget))] <--- Deleted

Conclusion

CS0739 is a housekeeping error.

  1. Search: Use "Find in Files" (Ctrl + Shift + F) to search for the specific type name mentioned in the error.
  2. Consolidate: Ensure there is only one [assembly: TypeForwardedTo(...)] line for that type in the project.
Navigation