.NET
Microsoft Technologies based on the .NET software framework.
3,572 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I wrote a C++/CLI Assembly and use the [ExtensionAttribute],coding like this:
using namespace System::Runtime::CompilerServices;
namespace ExFunLibWithCli {
public ref class ClassBase
{
public:
int BaseFun()
{
return 32;
}
};
[ExtensionAttribute]
public ref class ClassBaseExtensions abstract sealed
{
public:
[ExtensionAttribute]
static int ExtensionFunc(ClassBase^ cb)
{
return 64;
}
};
}
In another C# .NET project,I add the Assembly generated by this code to be referenced and coding like:
static void Main(string[] args)
{
var cb = new ClassBase();
int res = cb.ExtensionFunc();
}
It compiles and works well!
Now I create another VB .NET project,and do the same thing:
Sub Main()
Dim cb = New ClassBase
Dim res = cb.ExtensionFunc() 'this line compiles failed
Dim res = ClassBaseExtensions.ExtensionFunc(cb) 'this line can compiles and work well,but I want to use ClassBase directly
End Sub
btw,When I use C# to write the class and functions decorated by [ExtensionAttribute],and use it in the same VB.NET project,it also compiles and work well.
So i'm really confused about it.
Try adding this line to your C++/CLI code (or to AssemblyInfo.cpp, which is usually present):
[assembly:Extension];
Then rebuild the projects.