Schu23

I am a VB programmer, but forced to work with C# class for this project in VS 05. I have 2 projects in my solution: "CSharpLibrary" and "Test2". In Test2 I have a aspx page that has a code-behind in VB that is calling the CSharpLibrary class. While I have done this many times with VB to VB calls, this time it is not working and I can't see why not.

Here is the top lines of code from the "RetrieveContent.cs" class:

...

namespace RetrieveContent

{

/// <summary>

/// Summary description for Class1.

/// </summary>

class RetrieveContent

{

[STAThread]

static void Main(string[] args)

{

try

...

I ran 'build' on the class which ran without error, then went to my Test2 project and referenced the DLL it built. I can't dimension the class in my code. I would expect to write:

Dim myVariable as new RetrieveContent

but it can't find RetrieveContent. I've tried a number of othere possibilities but nothing is referencing that class so I can use it. What is the proper way to reference a C# class from VB. What am I doing wrong

Scott



Re: Visual C# General Referencing a class written in C#

H. Tony

what's the namespace your csharp code use if you have both projects in the solution, it might be better to add project reference instead of just the dll, but that wont hurt either.

you can either call namespace.RetrieveContent or add using namespace to your code if it's not already done.






Re: Visual C# General Referencing a class written in C#

OmegaMan

Two things
  1. The class you want is not marked Public, hence you will not be able to access it outside of its assembly.
  2. Make sure that cls compliance is enforced by placing

    [ assembly: CLSCompliant( true ) ]

    in one of the cs files. See this on why it may be important Writing CLS-Compliant Code
#1 is your primary problem.

Note I found this helpful when I needed to do the opposite VB.Net work from C#: VB.Net and C# Comparison . Its a side by side example comparison of the two Languages. Find what you are use to in the language you know, then see its opposite syntax on the other side.





Re: Visual C# General Referencing a class written in C#

boban.s

Schu23 wrote:

I am a VB programmer, but forced to work with C# class for this project in VS 05. I have 2 projects in my solution: "CSharpLibrary" and "Test2". In Test2 I have a aspx page that has a code-behind in VB that is calling the CSharpLibrary class. While I have done this many times with VB to VB calls, this time it is not working and I can't see why not.

What is the proper way to reference a C# class from VB. What am I doing wrong

Scott



There should be no difference on using C# class library or VB class library. If you express the same thing in C# as you do in VB, then using the library is completely equal. As OmegaMan suggested, first you have to mark the class as public. Next change the name of the class to be something different then part of your namespace, in this case your namaspace have one part from which that part is equal as class name. That is not alowed.






Re: Visual C# General Referencing a class written in C#

Schu23

As shown in the sample it goes;

Namespace...

Class...

[STAThread]

static void Main(string[] args)

{

try

I guess I am confused by your response. Should this be different Also, I don't see a "public" indicator. Shouldn't that be on the Class line or 'static void...' line, or something





Re: Visual C# General Referencing a class written in C#

Schu23

OK, I changed the code to read:

namespace RetrieveContent

{

Public class GetContent

and that did it! I will keep working on it and post a new thread if I hit a new problem. Thank you everyone! Smile

Scott