Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Multi dimensional arrays in C# and in C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hans - 02 May 2005 12:48 GMT
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?
  }
}
Kapil Khosla [MSFT] - 02 May 2005 17:27 GMT
Signature

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
[quoted text clipped - 45 lines]
>   }
> }

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 - 03 May 2005 07:00 GMT
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.

> >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
[quoted text clipped - 58 lines]
> Thanks,
> Kapil
Kapil Khosla [MSFT] - 03 May 2005 22:11 GMT
> The code compiles alright, but when debugging, the assembly loader throws
> exception System.TypeLoadException:
[quoted text clipped - 75 lines]
> > 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
Hans - 04 May 2005 11:51 GMT
> > The code compiles alright, but when debugging, the assembly loader throws
> > exception System.TypeLoadException:
[quoted text clipped - 80 lines]
> 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.
Hans - 11 May 2005 13:28 GMT
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???

> >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
[quoted text clipped - 58 lines]
> Thanks,
> Kapil
Kapil Khosla [MSFT] - 13 May 2005 23:30 GMT
> I keep getting
> Message    "Method get_MyProperty in type MyNamespace.MyImplementation from
[quoted text clipped - 65 lines]
> > 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
Kapil Khosla [MSFT] - 02 May 2005 21:46 GMT
> 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
[quoted text clipped - 43 lines]
>    }
> }

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.