Create an object

G

Guest

I am new to VB.NET. Anyone could give a hint? Thanks.
What is the problem about the following code:

Dim myPrincipal As CustomPrincipal = New CustomPrincipal(id, roles)

where CustomPrincipal is constructor defined as
Public Sub CustomPrincipal(ByVal identity As IIdentity, ByVal roles As
String())

the error message:
Too many arguments to 'Public Sub New()'.
 
K

Kevin Spencer

A Sub is not a class. The New Operator is for creating instances of classes.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
M

msnews.microsoft.com

Hi
I am a new ASP.NET programmer

In VB.NET the constructor name should be New and not the class name (C#
constructor name is the class name)

If there is no constructor declared with New keyword then the runtime will
create a default parameterless constructor for you.

So the solution may be:

One: change your constructor name to New instead of CustomPrincipal

Dim myPrincipal As CustomPrincipal = New CustomPrincipal(id, roles)
where CustomPrincipal is constructor defined as
Public Sub New(ByVal identity As IIdentity, ByVal roles As String())


or

Two create the object without any arguments passed to it


Dim myPrincipal As CustomPrincipal = New CustomPrincipal()
where CustomPrincipal is constructor defined as
Public Sub CustomPrincipal(ByVal identity As IIdentity, ByVal roles As
String())
 
M

Matt Berther

Hello David,

I think you need to define the constructor as

Public Sub New(ByVal identity As IIdentity, ByVal roles As String())
 
K

Karl Seguin

As kevin says, you need to create a constructor...

Publc Sub New(ByVal identity As IIdentity, ByVal roles As String())

perhaps you are used to C# where the constructor is the name of the
class...in VB.Net, you use the New keyword as the constructor name...

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
P

Patrice

Using the name of the class for the constructor is a (C#) language
convention. In VB.NET contrcutors are using always the name "New"...

Patrice
 
C

Cyn

Try

Dim myPrincipal as New CustomPrincipal(id, roles)

I assume your parameters are of the correct type

Hope that helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top