overload failed - no 'new' available

J

Josh Golden

i have a solution with 2 projects in it, project a and b. project a will be
a dll, but for now exists in the solution. projectB references projectA.
projectA has a dataset with one datatable in it, dataTable1.

From within projectA, in any class or method I have

private x as new ProjectA.dataTable1 -- and this works fine.

but in projectB, when I type
Private y as new ProjectA.dataTable1 -- I get the message
Overload resolution failed because no 'New' is accessible.

I don't get it. I have the right imports, references, etc.

what could it be?
 
J

Jay B. Harlow [MVP - Outlook]

Josh,
Is the Sub New of dataTable1 declare as Public?

It sounds like you made Sub New "Friend" in dataTable.

' this will fail in projectB
Public Class dataTable1

Friend Sub New()
End Sub

End Class

' this will succeed in projectB
Public Class dataTable1

Public Sub New()
End Sub

End Class

Hope this helps
Jay
 
J

Josh Golden

That sounds possible, I'm never sure when to use friend, but how could I
have done that? I added the dataset and the datatable through the gui.
LIke Project - Add New Item - DataSet. then i double-clicked it and hand
entered the datatable. how is it then set as friend? it looks to be an
xsd?

Josh
 
J

Jay B. Harlow [MVP - Outlook]

Josh,
How's that go "That's a horse of a different color".

VS.NET 2002 or VS.NET 2003?

Using VS.NET 2003 I do not see the behavior you are experiencing.

I do however need to prefix table names with the dataset name, in both
projects:

private x as New ProjectA.DataSet1.DataTable1

In ProjectA, the ProjectA is optional.

You didn't name the DataSet the same as your Project did you?

I started naming my DataSets something like "InvoiceDataSet" to avoid
"Invoice" colliding with other names...

Hope this helps
Jay
 
R

Richard Myers

Hi Josh,

Use Friend to scope an object when you only want that object to be visible
to other objects from the same assembly. You do this to prevent other
objects from another assembly from creating instances of classses when they
shouldn't. This also allows a cleaner namespace and clearly signals to other
developers how that assembly and the classes within it are supposed to be
used.

The designer automatically sets the Scope of a dataset encapsulated table to
Friend. If you look at the .vb for your dataset, by expanding the XSD File>
..Vb File, and scroll through the designers code you'll see your datatable is
scoped at Friend. Hence the reason you cannot see it from another assembly.

Your design sounds a little bung. If you just want a datatable then inherit
from it, instead of creating a dataset and then not using it.

Public MyTable
inherits Datatable

......

If you need to access the table and dont wish to directly inherit from
Datatable then you should be dimming up an instance of your Project A
dataset, not datatable, in project B.

dim ds as new dsWithTheTableIwanttoUseInIt()
ds.Table1(2).MyColumn="Blah Blah"


hth
Richard
 

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

Top