Author Topic: ExtensionAttribute is ambiguous  (Read 2658 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
ExtensionAttribute is ambiguous
« on: July 01, 2014, 09:11:29 AM »
Hi all,

I had a requirement to switch the target framework of my AutoCAD Class Library to .NET 4.5 because of some DLL's for our ERP system.

When I switched the target framework from 4.0 to 4.5 my extension methods have errors now saying 'ExtensionAttribute' is ambiguous in the namespace 'System.Runtime.CompilerServices'.

Anyone else run across this?

Thanks,

Ted

TJK44

  • Guest
Re: ExtensionAttribute is ambiguous
« Reply #1 on: July 17, 2014, 08:36:16 AM »
Attached is a screenshot of what I see when I search for ExtensionAttribute in the Object Browser. Does anyone else see the same thing?

n.yuan

  • Bull Frog
  • Posts: 348
Re: ExtensionAttribute is ambiguous
« Reply #2 on: July 17, 2014, 10:28:42 AM »
The class "System.Runtime.CompilerServices.ExtensionAttribute" in .NET4.5x has been moved from assembly "System.Core.dll" (.NET4.0 or earlier) to "mscorlib.dll". However, this fact alone probably is not the cause of your problem.

At first, I thought it could be that your solution may have both projects for earlier AutoCAD based on .NET4.0 and projects for AutoCAD 2015 based on .NET 4.5x. However, I created a test solution to one project based on .NET 4.51 targeting Acad2015 and one project based on .NET4.0 targeting Acad2012. Both projects have extension methods. and both projects build OK. If I search Object Browser, I only find one System.Runtime.CompilerServices.ExtensionAttribute (in mscorlib.dll, .NET4.5). In this case, I use C#. That means, to create extension method, I do not have to import namespace "System.Runtime.CompilerServices" as "using System....".

However, I also did the exactly the same 2 projects with VB.NET. In the extension method MODULE, I need to "Import System.Runtime.CompilerServices", and have to explicitly use <Extension()> attribute to decorate the extension methods. Again, the solution still build OK. But search "ExtensionAttribute" in Object Browser yields 2 items as shown in your attached picture. Obviously, you are using VB.NET, and your solution has projects based on .NET4.5x and .NET4.0 or earlier. This could be where the problem comes from, although it is OK in my fairly simple test solution. It also seems C# has its advantage over VB.NET, at lease in terms of doing extension methods :-(.

TJK44

  • Guest
Re: ExtensionAttribute is ambiguous
« Reply #3 on: July 18, 2014, 08:22:52 AM »
This is a pretty old solution, so I just created a new one and added all the files from the solution that wasn't working and re-imported my references and voila.

It could have something to do with the fact that it was created using the AutoCAD Visual Studio wizard...