Skip to content

Roslyn C# compiler doesn't recognize extension methods from most libraries written in C++/CLI and other CLI languages #365

@gafter

Description

@gafter

@latkin reported:

The Roslyn C# compiler, unlike the legacy compiler, requires an assembly-level ExtensionAttribute in order for extension methods defined in that assembly to be considered. The legacy compiler only required method-level and class-level ExtensionAttributes.

This is a breaking change that was deemed acceptable due to perf wins. It did not affect C# and VB libraries, since C# and VB compilers have always provided special support for extension methods, by automatically adding the assembly-level ExtensionAttribute for you even if you leave it out.

Besides C# and VB, though, I don't know of any other CLI languages that have special compiler support for defining extension members. C# usage of libraries from all of these languages is now broken by Roslyn.

F# was noticed early, and has already been special-cased to preserve back-compat.

C++/CLI suffers from the same issue, though, and is still broken. All online documentation and sample code I can find leaves out the assembly-level attribute, because it was never needed in the past. Even the estimable Jon Skeet forgets that the assembly-level attribute is required: http://stackoverflow.com/a/995154/1366219 Another highly-voted answer here: http://stackoverflow.com/a/6012771/1366219

Other CLI languages like Nemerle, Boo, Iron*, etc will also be affected.

Metadata

Metadata

Assignees

Labels

Area-CompilersBugLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedTenet-CompatibilityViolation of forwards/backwards compatibility in a design-time piece.Verified

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions