none
"Use new keyword to create an object instance" exception in vb.net RRS feed

  • Question

  • Hello All,

    I am new in vb.net and getting exception "Use new keyword to create an object instance" when I am calling shared method in vb.net. Here is code snippet -

    protected wl as Worklist
    wl = Generic.ReadWorkList(...) 'Getting error here

    Generic.ReadWorkList is shared method and defined as -
            public shared function Generic.ReadWorkList(...

    Please help to resolve this. Thanks in advance

    Wednesday, April 22, 2015 10:22 AM

Answers

  • You are writing the call to ReadWorkList with (...) as the parameters list. Does this mean you are actually passing parameters that you have just omitted from your example?

    If so, maybe the error is occurring due to one of your parameters. Post the full line with parameters.


    • Marked as answer by Harish83 Wednesday, April 22, 2015 3:18 PM
    Wednesday, April 22, 2015 10:57 AM

All replies

  • Generic, i.e. the name of the left-hand side of the dot (.) refers to the name of the class in which the shared function is defined. Please refer to the following sample code:

    Generic.vb

    Public Class Generic
        Public Shared Function ReadWorkList() As String
            Return "abc"
        End Function
    End Class

    Usage:

            Dim s As String = Generic.ReadWorkList()

    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Wednesday, April 22, 2015 10:27 AM
  • Thanks Magnus for quick reply.

    Yes code is in the same format as you explained but still I am getting this issue..

    protected wl as Worklist
    wl = Generic.ReadWorkList(...) 'Getting error here

    ReadWorkList function defined inside Generic class as -

    public shared function Generic.ReadWorkList(...) as Worklist

    Wednesday, April 22, 2015 10:35 AM
  • You are writing the call to ReadWorkList with (...) as the parameters list. Does this mean you are actually passing parameters that you have just omitted from your example?

    If so, maybe the error is occurring due to one of your parameters. Post the full line with parameters.


    • Marked as answer by Harish83 Wednesday, April 22, 2015 3:18 PM
    Wednesday, April 22, 2015 10:57 AM
  • Thanks RJP1973,

    I found one of the parameter was creating this issue.

    Wednesday, April 22, 2015 3:20 PM