I have two Perl modules which I want to expose as object types to C#. One of them constructs objects of the other type and returns it using a method as shown below. I'm including a reference to Type2.dll in Type1.dll, and referencing them both in C#. As the code shows I can construct a Type2 object directly from C#, but I can't return a Type2 object that was constructed by a method in Type1. Any ideas?
(Cross-posted from http://community.activestate.com/forum/return-perl-object-different-perl-class-c)
C#:
Type1 obj1 = new Type1(); // Works
Type2 test = new Type2(); // Works
Type2 obj2 = obj1.make2();
// Fails: System.InvalidCastException: Unable to cast object of type
// 'PerlRunTime.SV' to type 'Type2' at Type1.make2()
Perl: Type1.pm
package Type1;
use strict;
use Type2;
=for interface
[interface: pure]
static Type1();
Type2 make2();
=cut
sub new {
my $class = shift;
return bless {}, $class;
}
sub make2 {
my $this = shift;
return Type2->new();
}
1;
Perl: Type2.pm
package Type2;
use strict;
=for interface
[interface: pure]
static Type2();
=cut
sub new {
my $class = shift;
return bless {}, $class;
}
1;