views:

157

answers:

1

I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code is used to update a TIMESTAMP column in an Oracle database, given a record ID and the System::DateTime object which is the .NET compatible data type for Oracle's TIMESTAMP type.

The method I am calling has the following prototype:

bool ChangeJobUpdateDate (int jobIdIn, System::DateTime^ updateDateIn)

I've added a reference to this DLL project in a test project that I made; I'm writing the tests in C#. However, when I try to call this method from the C# unit test project, the function appears to have the following method declaration (via intellisense):

bool ChangeJobUpdateDate (int jobIdIn, ValueType updateDateIn)

I'm admittedly not that familiar with C++/CLI, so is there something I'm missing?

+1  A: 

I suspect it's because you're using DateTime^ instead of just DateTime. It's a value type, so why are you trying to use a reference?

C# doesn't have any way of representing the boxed reference type associated with a value type, so the best it can do is ValueType - I suspect that's what's happening, although I can't say for sure due to my lack of experience with C++. Try just DateTime and see how that looks...

Jon Skeet
David Ipsen
That's pretty much it. C++/CLI actually does encode the real type of the value into the signature - in this case, in IL, the complete type would be: `class [mscorlib]System.ValueType modopt([mscorlib]System.DateTime) modopt([mscorlib]System.Runtime.CompilerServices.IsBoxed)` - which is how C++/CLI compiler later knows the correct type and will do proper typechecking - but C# just ignores all `modopt`'s and treats it as a plain `ValueType`.
Pavel Minaev
@Pavel: Thanks for the detail. I was really just making an educated guess. Feel free to edit all this goodness into my answer - or add your own :)
Jon Skeet