Link to home
Start Free TrialLog in
Avatar of brettr
brettr

asked on

Help with VB.NET to C# conversion.

I'm having problems with this VB.NET to C# conversion:

[VB.NET]
        Dim UDCPrinter As New UDCWRAPPERLib.Printer
        Dim UDCProfile As UDCWRAPPERLib.Profile

        UDCPrinter.PrinterName = "Universal Document Converter"
        UDCProfile = UDCPrinter.Profile(UDCPrinter.DefaultProfile)

[C#}
UDCWRAPPERLib.Printer UDCPrinter = new UDCWRAPPERLib.Printer();
  UDCWRAPPERLib.Profile UDCProfile;

  UDCPrinter.PrinterName = "Universal Document Converter";
  UDCProfile = UDCPrinter.get_Profile();

Error is on the last line:
No overload for method 'get_Profile' takes '0' arguments

Object browser tree looks like this:
UDCWRAPPERLib
    Printer (interface)
        IPrinter (interface)

get_Profile(string) is a member of the last node.

I'm using get_Profile because .Profile isn't available in C#.  Why does the above error occur is "string" type is required?

I have tried:
UDCProfile = UDCPrinter.get_Profile(UDCPrinter.DefaultProfile);
and get:
Cannot implicitly convert type 'object' to 'UDCWRAPPERLib.Profile'

Any suggestions?

Thanks,
Brett
ASKER CERTIFIED SOLUTION
Avatar of 3Mann
3Mann

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brettr
brettr

ASKER

Thanks.  That did successfully compile.  I'm just getting error on the default profile name:
Additional information: Cannot receive name of the default profile

I don't have the VB version with me here but I believe the default is actually getting set.  I'll check it tomorrow morning.

How did you know to cast the get_Profile() from the error given?
the message: "Cannot implicitly convert type 'object' to 'UDCWRAPPERLib.Profile'"

it just says that .NET could not automatically convert it to the desired type. so we do manual conversion thus casting :)

good luck
Avatar of brettr

ASKER

VB.NET seems to do much implied casting vs. C#.  Is that true?
Nope, in VB.NET UDCPrinter.Profile(string) will return UDCWRAPPERLib.Profile object. But in C# get_Profile() just return object, then you must cast to UDCWRAPPERLib.Profile

Following code from 3Mann was right:
UDCProfile = (UDCWRAPPERLib.Profile)UDCPrinter.get_Profile(UDCPrinter.DefaultProfile);
Avatar of brettr

ASKER

Why does C# return only an object and not UDCWRAPPERLib.Profile object?
object is the equivalent of VB's variant

i'm not familiar with UDCWRAPPERLib.  I'm not sure why it returns object.  maybe so you can cast it to compatible types other than UDCWRAPPERLib.Profile.

cheers :)