Question
Trouble with arguments in .NET objects
I'm having a horrible time integrating with a 3rd party API
in .NET 1.1 calling functions with arguments that are not simple
datatypes. I understand the limitations of not being able to pass
pointers/refs, but even simple datatypes I think are not working.
It's impossible to debug because CF reports that the method with
the supplied arguments was unable to be found. I've tried every
iteration of JavaCast and think I fully understand the limitations
of the .NET integration, but it's still impossible to know if the
casting of specific arguments is getting fouled. I even look to see
how CF expects a method's arguments to be cast by doing a simple
CFDUMP on the object that contains the method and seeing how the
cfdump reports the arguments to be cast. It almost appears as
though .NET "bool" datatypes might be fouling it up - albeit I
tried every iteration of JavaCast("boolean", ...) I could muster
and the method is still not found. This seems to be the case with
methods in a .NET object, overloaded constructors with arguments
and even Set_Func(Value) functions.
I tried to come up with a simple example of how this does not work, and the most generic I could come up with is trying to instantiate the System.DateTime with a specific date. I completely understand the fact that CF automatically can convert native CF dates to System.DateTime but my example shows the problem:
<cfset arrivalDate = createObject(".NET", "System.DateTime").init(JavaCast("int", 2007), JavaCast("int", 9), JavaCast("int", 1))>
If you look at the introspection/reflection of the System.DateTime object you'll see a simple constructor as: public DateTime(int year, int month, int day);
If you try to use .init(2007, 9, 1) in the cfset for this object, you'll get: Unable to find a constructor for class System.DateTime that accepts parameters of type ( java.lang.String, java.lang.String, java.lang.String ).
if you use .init(JavaCast("int", 2007), JavaCast("int", 9), JavaCast("int", 1)) in the cfset for this object you'll get: Unable to find a constructor for class System.DateTime that accepts parameters of type ( java.lang.Integer, java.lang.Integer, java.lang.Integer ).
Clearly the claimed CF auto-conversion of CF integer -> java.lang.Integer -> System.Int32 does not work in this instance of trying to instantiate a System.DateTime. This also leads me to believe that there are other problems with automatic conversion of complex arguments even considering the limitations presented at: http://livedocs.adobe.com/coldfusion/8/htmldocs/dotNet_05.html#1163842
Any help is much appreciated!
I tried to come up with a simple example of how this does not work, and the most generic I could come up with is trying to instantiate the System.DateTime with a specific date. I completely understand the fact that CF automatically can convert native CF dates to System.DateTime but my example shows the problem:
<cfset arrivalDate = createObject(".NET", "System.DateTime").init(JavaCast("int", 2007), JavaCast("int", 9), JavaCast("int", 1))>
If you look at the introspection/reflection of the System.DateTime object you'll see a simple constructor as: public DateTime(int year, int month, int day);
If you try to use .init(2007, 9, 1) in the cfset for this object, you'll get: Unable to find a constructor for class System.DateTime that accepts parameters of type ( java.lang.String, java.lang.String, java.lang.String ).
if you use .init(JavaCast("int", 2007), JavaCast("int", 9), JavaCast("int", 1)) in the cfset for this object you'll get: Unable to find a constructor for class System.DateTime that accepts parameters of type ( java.lang.Integer, java.lang.Integer, java.lang.Integer ).
Clearly the claimed CF auto-conversion of CF integer -> java.lang.Integer -> System.Int32 does not work in this instance of trying to instantiate a System.DateTime. This also leads me to believe that there are other problems with automatic conversion of complex arguments even considering the limitations presented at: http://livedocs.adobe.com/coldfusion/8/htmldocs/dotNet_05.html#1163842
Any help is much appreciated!