Multi dimensional arrays in C# and in C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}
 
--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Hans said:
I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour
of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how
I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}


I cannot repro your behavior. Could it be that you are not referencing all
your assemblies. This is how verified your repro. I just renamed your
MyImplementation.h to MyImplementation.cpp.

csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs

RESULT: Successful compile with no exception ?

Thanks,
Kapil
 
Hans said:
I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}


Can you try reproing with the following
csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs


Your exact code works for me,
Thanks,
Kapil
 
The code compiles alright, but when debugging, the assembly loader throws
exception System.TypeLoadException:
"Method get_MyProperty in type MyNamespace.MyImplementation from assembly
MyImplementation, Version=, Culture=, PublicKeyToken= does not have an
implementation."

When I change
double[ , ] MyProperty {get;}
to
double[ ] MyProperty {get;}

(at all places), the assembly loads without a problem...

Have you tried to execute the code or did you compile it only?

regards, Hans.

Kapil Khosla said:
--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Hans said:
I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour
of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how
I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}


I cannot repro your behavior. Could it be that you are not referencing all
your assemblies. This is how verified your repro. I just renamed your
MyImplementation.h to MyImplementation.cpp.

csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs

RESULT: Successful compile with no exception ?

Thanks,
Kapil
 
Hans said:
The code compiles alright, but when debugging, the assembly loader throws
exception System.TypeLoadException:
"Method get_MyProperty in type MyNamespace.MyImplementation from assembly
MyImplementation, Version=, Culture=, PublicKeyToken= does not have an
implementation."

When I change
double[ , ] MyProperty {get;}
to
double[ ] MyProperty {get;}

(at all places), the assembly loads without a problem...

Have you tried to execute the code or did you compile it only?

regards, Hans.

Kapil Khosla said:
--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Hans said:
I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour
of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how
I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}


I cannot repro your behavior. Could it be that you are not referencing all
your assemblies. This is how verified your repro. I just renamed your
MyImplementation.h to MyImplementation.cpp.

csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs

RESULT: Successful compile with no exception ?

Thanks,
Kapil


I did execute the app last time too and got no exception. I am working with
beta2 though, what compiler/IDE are you working on?
Thanks
Kapil
 
Kapil Khosla said:
Hans said:
The code compiles alright, but when debugging, the assembly loader throws
exception System.TypeLoadException:
"Method get_MyProperty in type MyNamespace.MyImplementation from assembly
MyImplementation, Version=, Culture=, PublicKeyToken= does not have an
implementation."

When I change
double[ , ] MyProperty {get;}
to
double[ ] MyProperty {get;}

(at all places), the assembly loads without a problem...

Have you tried to execute the code or did you compile it only?

regards, Hans.

Kapil Khosla said:
--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour
of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how
I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}



I cannot repro your behavior. Could it be that you are not referencing all
your assemblies. This is how verified your repro. I just renamed your
MyImplementation.h to MyImplementation.cpp.

csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs

RESULT: Successful compile with no exception ?

Thanks,
Kapil


I did execute the app last time too and got no exception. I am working with
beta2 though, what compiler/IDE are you working on?
Thanks
Kapil

Developer studio 7.1.3088,
Microsoft Visual C# .NET 69461-335-0000007-18487,
Microsoft Visual C++ .NET 69461-335-0000007-18487

regards, Hans.
 
I keep getting
Message "Method get_MyProperty in type MyNamespace.MyImplementation from
assembly InterfaceImplementation, Version=1.0.1957.24022, Culture=neutral,
PublicKeyToken=null does not have an implementation."

Can anybody help me out???

Kapil Khosla said:
--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Hans said:
I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour
of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how
I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}


I cannot repro your behavior. Could it be that you are not referencing all
your assemblies. This is how verified your repro. I just renamed your
MyImplementation.h to MyImplementation.cpp.

csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs

RESULT: Successful compile with no exception ?

Thanks,
Kapil
 
Hans said:
I keep getting
Message "Method get_MyProperty in type MyNamespace.MyImplementation from
assembly InterfaceImplementation, Version=1.0.1957.24022, Culture=neutral,
PublicKeyToken=null does not have an implementation."

Can anybody help me out???

Kapil Khosla said:
--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Hans said:
I have encapsultated old C/C++ code in a mixed mode C++ module (Project 2).
In my C# app (project 3) I instanciate a managed C++ class. The behaviour
of
the C/C++ class is defined by an interface (Project 1). I wanted to add a
getter property to a multi dimension array, but the assembly loader keeps
telling me that the property is not implemented...
When I make a single dimensional array out of it, it works fine...

I added a simplified example of what I did below. Can anybody tell me how
I
can get this working???

Thanx, Hans.

file 'IMyInterface.cs' (Project 1)
namespace MyNamespace
{
public interface IMyInterface
{
double[,] MyProperty {get;}
}
}

file 'MyImplementation.h' (Project 2, MyImplementation.cpp is omitted)
using namespace MyNamespace;
[assembly:System::CLSCompliant(true)];
namespace MyNamespace
{
public __gc class MyImplementation: public MyNamespace::IMyInterface
{
private:
double m_MyMember __gc [,];
public:
__property double get_MyProperty() __gc[,] {return m_MyMember;}
}
}

file 'MyApp.cs' (Project 3)
namespace MyNamespace
{
...
...
void MyMethod()
{
IMyInterface myInterface = new MyImplementation(); // causes an
exception...
// How can I get this working?
}
}


I cannot repro your behavior. Could it be that you are not referencing all
your assemblies. This is how verified your repro. I just renamed your
MyImplementation.h to MyImplementation.cpp.

csc /t:library IMyInterface.cs
cl /clr:oldSyntax /LD MyImplementation.cpp
csc /r:MyImplementation.dll /r:IMyInterface.dll MyApp.cs

RESULT: Successful compile with no exception ?

Thanks,
Kapil



Hi Hans,
I finally got hold of Everett and tried your sample and you are right, I do
get the
same exception with Everett CLR.

The reason is due to a bug in the Everett CLR which has now been fixed with
later release. I could not really find a good work around in Everett. I am
pretty sure the
code has no issues in beta2 so if you can updgrade your solution to Beta2
that would be ideal.

Let me know if you have questions.
Kapil
 
Back
Top