non-shared member errors

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I have a program I am trying to compile into a dll and am getting a bunch
of: the following errors:

error BC30469: Reference to a non-shared member requires an object
reference.

At first, I thought it was because I had the sub set as shared, but I get
the same error if it take the Shared out.

What is causing these errors?

**************************************************************************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.SessionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports Microsoft.VisualBasic

Namespace MyComponents

Public Class Emails

Shared sub sendTheEmail( )
dim URLPath As String = Left(request.path, InStrRev(request.path, "/") -
1)
Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(MapPath("mail.htm"))
end sub

End Class
End Namespace
**********************************************************************

And got the following errors:
*******************************************************************************************
C:\Inetpub\wwwroot\Development>vbc /t:library emailClassgood.vb
/r:system.web.dl
l /r:system.data.dll /r:system.dll /r:Microsoft.VisualBasic.dll
Microsoft (R) Visual Basic .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.

C:\Inetpub\wwwroot\Development\EmailClassgood.vb(22) : error BC30469:
Reference
to a non-shared member requires an object reference.

dim URLPath As String = Left(request.path, InStrRev(request.path,
"/") -
1)
~~~~~~~

C:\Inetpub\wwwroot\Development\EmailClassgood.vb(22) : error BC30469:
Reference
to a non-shared member requires an object reference.

dim URLPath As String = Left(request.path, InStrRev(request.path,
"/") -
1)
~~~~~~~

C:\Inetpub\wwwroot\Development\EmailClassgood.vb(24) : error BC30469:
Reference
to a non-shared member requires an object reference.

objStreamReader = File.OpenText(MapPath("mail.htm"))
~~~~~~~
******************************************************************************************
Thanks,

Tom
 
I assume that the class Emails inherits from Page, though that's not shown
here. The trouble is that you refer to the Request object inside a shared
method. A shared method does not have access to instance-specific variables
like Request. The Request object is unique for each instance of a Page
object. So a shared method can't refer to it. It can only refer to objects
that are shared across all instances of a given class. So if your class had
declared a class-level shared variable, then your shared method could refer
to it.
 
Dan Nuttle said:
I assume that the class Emails inherits from Page, though that's not shown
here. The trouble is that you refer to the Request object inside a shared
method. A shared method does not have access to instance-specific
variables
like Request. The Request object is unique for each instance of a Page
object. So a shared method can't refer to it. It can only refer to
objects
that are shared across all instances of a given class. So if your class
had
declared a class-level shared variable, then your shared method could
refer
to it.

But if I take the "Shared" of the Sub line, it gives me the same errors?

If I change:

Shared sub sendTheEmail( )

to

sub sendTheEmail( )

It is the same.

Is there somewhere I can look to find out the difference between shared and
unshared for my asp.net pages to find out the best way to build these?

Thanks,

Tom
 
Back
Top