Help with VB.NET to C# conversion.

Posted on 2005-05-04
Last Modified: 2008-02-07
I'm having problems with this VB.NET to C# conversion:

        Dim UDCPrinter As New UDCWRAPPERLib.Printer
        Dim UDCProfile As UDCWRAPPERLib.Profile

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

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:
    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?

Question by:brettr
    LVL 1

    Accepted Solution

    try casting:

    >I have tried:
    >UDCProfile = UDCPrinter.get_Profile(UDCPrinter.DefaultProfile);

    UDCProfile = (UDCWRAPPERLib.Profile)UDCPrinter.get_Profile(UDCPrinter.DefaultProfile);

    also, just make sure that get_Profile() returns an object compatible to 'UDCWRAPPERLib.Profile'

    hope that helps =)

    Author Comment

    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?
    LVL 1

    Expert Comment

    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

    Author Comment

    VB.NET seems to do much implied casting vs. C#.  Is that true?
    LVL 13

    Expert Comment

    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);

    Author Comment

    Why does C# return only an object and not UDCWRAPPERLib.Profile object?
    LVL 1

    Expert Comment

    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 :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now