CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Referencing Classes

    I have been trying to referenceClass library I have in a windows form application I am currently working on but it's not working! I created the DLL file by going to Projects > Build Solution and even tried using the Clean build and other misc options to create the DLL but nothing is working.After I add the DLL file as a reference in my Windows application, intellisense still won't recognise the
    Code:
    using ClassX
    statement.I even made sure both programs target the same .NET 4.0 network.Does anyone have any idea of what could I be doing wrong?

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Referencing Classes

    Is "ClassX" the name of a public class in the .DLL?

    If so, what is the "NameSpace" of the .dll?

    In your "Using", it needs to be the NameSpace. Then you will need to initialize your class.

  3. #3
    Join Date
    Jul 2012
    Posts
    4

    Re: Referencing Classes

    Quote Originally Posted by sotoasty View Post
    Is "ClassX" the name of a public class in the .DLL?

    If so, what is the "NameSpace" of the .dll?

    In your "Using", it needs to be the NameSpace. Then you will need to initialize your class.
    "ClassX" is the name of the namespace of the library.I've just tried putting
    Code:
    Using ClassX.ClassY
    , where ClassY is the actual class i'm interested in using and it's still failing.

  4. #4
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Referencing Classes

    Could you post the top several lines of your "ClassY" code. Including the namespace and the Class declaration?

  5. #5
    Join Date
    Jul 2012
    Posts
    4

    Re: Referencing Classes

    Quote Originally Posted by sotoasty View Post
    Could you post the top several lines of your "ClassY" code. Including the namespace and the Class declaration?
    ClassY
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Complex_Numbers
    {
        class Complex : IEquatable<Complex>
    ClassX

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Deployment;
    using Complex_Numbers;
    
    
    namespace Control_System
    {

  6. #6
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Referencing Classes

    Have you tried

    "public class Complex"

  7. #7
    Join Date
    Jul 2012
    Posts
    4

    Re: Referencing Classes

    Quote Originally Posted by sotoasty View Post
    Have you tried

    "public class Complex"
    It worked!!! Thank you very much!!! I can't believe it was just an easy fix.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Referencing Classes

    Quote Originally Posted by KillaKem View Post
    It worked!!! Thank you very much!!! I can't believe it was just an easy fix.
    It worked because a class needs to be marked as public in order to be accessed outside its assembly.

    If you use that class inside an assembly, you can do so with it marked as public, private, or internal. Btw, declaring "class Complex" is the same as declaring "private class Complex".

    If you need to access a class or other entity from a different assembly, then you need to mark it as public.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured