Search code examples
c#datetimec++-clitypes

Calling C++/CLI Method with System::DateTime parameter requires 'ValueType' as a parameter?


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?


Solution

  • 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...