Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:04:28+00:00 2026-06-06T01:04:28+00:00

How can a single .NET assembly, targeting 2.0, 3.0, 3.5, 4.0, and 4.5 concurrently,

  • 0

How can a single .NET assembly, targeting 2.0, 3.0, 3.5, 4.0, and 4.5 concurrently, support extension methods for both C# and VB.NET consumers?

The standard suggestion is to add this:

namespace System.Runtime.CompilerServices
{
  public sealed class ExtensionAttribute : Attribute { }
}

This the approach suggested by more than one Microsoft employee and was even featured in MSDN magazine. It’s widely hailed by many bloggers as having ‘no ill effects’.

Oh, except it will cause a compiler error from a VB.NET project targeting .NET 3.5 or higher.

The authors of Microsoft.Core.Scripting.dll figured it out, and changed ‘public’ to ‘internal’.

namespace System.Runtime.CompilerServices
{
  internal sealed class ExtensionAttribute : Attribute { }
}

Which seemed to solve the VB compatibility issue.

So I trustingly used that approach for the latest version (3.2.1) of the widely-used ImageResizing.Net library.

But then, we start getting this compiler error (original report), more or less randomly, for certain users targeting .NET 3.5+.

Error 5 Missing compiler required member
'System.Runtime.CompilerServices.ExtensionAttribute..ctor'

Because the MSBuild/VisualStudio compiler apparently doesn’t bother to look at scoping rules when resolving naming conflicts, and the order of assembly references plays a not-quite-docuemented role, I don’t fully understand why and when this happens.

There are a few hacky workarounds, like changing the assembly namespace, recreating the project file, deleting/readding System.Core, and fiddling with the target version of the .NET framework. Unfortunately, none of those workarounds are 100% (except aliasing, but that’s an unacceptable pain).

How can I fix this while

  1. Maintaining support for extension method use within the assembly,
  2. Maintaining support for .NET 2.0/3.0
  3. Not requiring multiple assemblies for each .NET framework version.

Or, is there a hotfix to make the compiler pay attention to scoping rules?

Related questions on SO that don’t answer this question

  • C# Extension methods in .NET 2.0
  • Using Extension Methods with .NET Framework 2.0
  • strange warning about ExtensionAttribute
  • Ambigious reference for ExtensionAttribute when using Iron Python in Asp.Net
  • Should I support .NET 2.0?
  • Using extension methods in .NET 2.0?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:04:29+00:00Added an answer on June 6, 2026 at 1:04 am

    We ran into the same issue with IronPython. http://devhawk.net/2008/10/21/the-fifth-assembly/

    We ended up moving our custom version of ExtensionAttribute to its own assembly. That way, customers could choose between referencing our custom ExtensionAttribute assembly or System.Core – but never both!

    The other tricky thing is that you have to always deploy the ExtensionAttribute assembly – even if you don’t reference it in your project. Your project assemblies that expose extension methods will have an assemblyref to that custom ExtensionAttribute assembly, so CLR will get upset if it can’t be found.

    Given the hard requirement of .NET 2.0 support, I would think the best bet would be to simply not use extension methods at all. I’m not familiar with the ImageResizer project, but it sounds like this was a recent change in ImageResizer. How feasible would it be to change the extension methods to traditional static methods? We actually thought about that for IronPython/DLR, but it wasn’t feasible (We were merged with LINQ at that point and LINQ had made heavy use of extension methods for essentially its entire existence).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how do i cast a .net single to equivalent byte array that can be
In ASP.NET MVC, how can I create a single cookie and save multplie values
Now I can add single value or tubles to the pipeline, my next question
Can someone test this example and share the results? http://timothypowell.net/blog/?p=23 When I do: var
In .NET 2.0 (in this case VB), is there a standard API that'll serialize
I have a situation in which user can single tap a control, which show
Possible Duplicate: how to upload folder with php I know we can upload single
I can make a single row IKImageBrowserView by setting the [imageBrowser setContentResizingMask:NSViewWidthSizable]; but in
How can I write single UPDATE query to change value of COL1 to ‘X’
I was wondering if i can use a single query in sql server 2005

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.