How to use a class I developed?

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

I creates a .cs file that will be a library class called Recursive that
contains.
public static class Recursive{...

I tried to put it into App_Code but I already have VB files in there and the
compiler said the two types can not be compiled together.



So I put the file in the folder containing the .aspx/.vb pair that will use
it.

That is:

Folder1

zz.aspx+zz.vb

Recursive.cs



In zz.vb I try:

Dim r as

I expected to see Recursive show up in the list but it does not.

What am I doing wrong?



Thanks
 
I want to do some C# for the experience.


Mark Rae said:
First things first: if this is an ASP.NET app using VB.NET, why on earth
did you create a class file in C#...?
 
Mark Rae said:
Then do yourself a *HUGE* favour and create a new project with C# as the
server-side language...
Not sure that wasn't done for me. I never used class view but just read a
little about it and looking at it find there are two projects in it.

One C# containing the new class. The other is a VB project with all the VB
code from App_Code.

Is that what you referred to?


Thanks
 
Mark Rae said:
Then do yourself a *HUGE* favour and create a new project with C# as the
server-side language...

I never used class view but just read a
little about it and looking at it find there are two projects in it.

One C# containing the new class. The other is a VB project with all the VB
code from App_Code.

I only have one project showing in Solution Explorer.

The two and the one that I mentioned have the same name.

I created a new C# class library project with a new name.

Move the C# class to the new project and deleted it from the vb project.

Now two show in the Class View.

Which is nice in that I now have a separated library project.

I'll now need to figure out how to use it.






Thanks
 
Mark Rae said:
.

I'm struggling to work out what you're doing here...

Have you tried to add a new C# class to an existing VB project?

Or have you added a new C# class library project to an existing solution
which already creates a VB.NET project?

Got this just after posting.

Before my first post I added a C# class to an existing VB project.

After your post, I added a new C# library project to my solution which
contained the VB project and moved the C# class to it.
 
Mark Rae said:
Then do yourself a *HUGE* favour and create a new project with C# as the
server-side language...
What you suggested works well. I now have a library that is separate from
my pages. Nice.

It does not impact the job but I'm confused about the rules.

I got into trouble when I mixed a C# class with my website which I now
notice has a VB icon in class view.

But that same website has pages with C# code behind files and also pages
with VB code behind files.

It appears it's only VB in that it can only contain non-aspx VB classes (no
non-aspx cs classes) - the code behinds can be either?

Is that your understanding?

Thanks, this give more structure to the solution
 
Mark Rae said:
Then do yourself a *HUGE* favour and create a new project with C# as the
server-side language...

In case anyone else reads this thread it probably should include the
posibility if mixing VB and C# by creating sub directories in App_Code and
then including in web.config:
<compilation debug="false">
<codeSubDirectories>
<add directoryName="VBCode" />
<add directoryName="CSCode" />
</codeSubDirectories>
</compilation>
I suppose a separate dll is best when the routines are general purpose, as
in my case, and the above better if the routines are only good for the one
website - but I'm certainly not sure about that.
 
Mark Rae said:
I appreciate that you've found the hack with web.config, but I would
strongly advise you not to mix .NET languages in the same project...

Apart from the fact that it doesn't work with partial classes, there is no
benefit whatsoever in doing so...

If I understand what you mean by the "hack in weg.config" I think you're
saying there is a down side to using :
<compilation debug="false">
<codeSubDirectories>
<add directoryName="VBCode" />
<add directoryName="CSCode" />
</codeSubDirectories>
</compilation>

I'm pleased with the way I've set up two library procedures; one for VB and
one for C# and do not plan on changing. But I'd love to have your insight
into things and an courious about what is the downside to using two
subdirectories. The upside for a small project into which you want to
import previously written vb and C# routines is a simpler creation of the
solution. I'm not sure how the run time system manages in the two
situations. Anyway, why the strong advise to not use that existing
capability?

Thanks a lot
 
Back
Top