locked
Type error converting VB to C# RRS feed

  • Question

  • User1000638852 posted

    I am trying to convert some vb code to c# but I am stumped. In the following vb code there are no compilation problems because of the way vb is so forgiving about Types.

                        Dim t As Type, AGNSec As Object
                        t = Type.GetTypeFromProgID("AGNSecurity.Security")
                        AGNSec = Activator.CreateInstance(t)
                        Dim blnValid As Boolean


                        blnValid = AGNSec.VerifyLogin([params omitted])
                        AGNSec = Nothing

    When I convert this code to C# however, I get a compilation error at the AGNSec.VerifyLogin() line.

                        Type t = null;
                        object AGNSec = null;
                        t = Type.GetTypeFromProgID("AGNSecurity.Security");
                        AGNSec = Activator.CreateInstance(t);
                        bool blnValid = false;                   

                        //errors here in c#:
                        blnValid = AGNSec.VerifyLogin([params omitted]);
                        AGNSec = null;

    Is there a way of coding this in C# so that it does not error?

    Monday, December 29, 2014 9:52 AM

Answers

  • User397347636 posted

    Use the 'dynamic' keyword in C#:

    dynamic AGNSec = null;
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 29, 2014 10:05 AM

All replies

  • User397347636 posted

    Use the 'dynamic' keyword in C#:

    dynamic AGNSec = null;
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 29, 2014 10:05 AM
  • User1000638852 posted

    God bless you my friend. That worked!

    Monday, December 29, 2014 10:16 AM