2

I have created a DLL to house a class that I want to use across multiple applications, as well the DBML created by LINQ.

The problem I am having is that the class is not visible/usable from external applications when the compiled DLL is set as a reference, although all the LINQ objects are. Also, when I manually import the .cs file then I can use the class as expected.

I have built the class as static, and the code is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;
using System.Data;

namespace OsgShared
{
    static class GlobalClass
    {
        public static USER CurrentUser { get; set; }

        private static Dictionary<string,int> _SysDetIDs;
        public static Dictionary<string,int> SysDetIDs { get { return _SysDetIDs; } }

        private static Dictionary<string, int> _AccInfoTypeIDs;
        public static Dictionary<string, int> AccInfoTypeIDs { get { return _AccInfoTypeIDs; } }

        private static Dictionary<string, int> _AccGroupTypeIDs;
        public static Dictionary<string, int> AccGroupTypeIDs { get { return _AccGroupTypeIDs; } }

        private static Dictionary<string, int> _EntTypeIDs;
        public static Dictionary<string, int> EntTypeIDs { get { return _EntTypeIDs; } }

        /// <summary>
        /// Populates Dictionary objects containing database reference data
        /// </summary>
        public static void PopulateDictionaries()
        {
            _SysDetIDs = new Dictionary<string,int>();
            _AccInfoTypeIDs = new Dictionary<string,int>();
            _AccGroupTypeIDs = new Dictionary<string,int>();
            _EntTypeIDs = new Dictionary<string, int>();

            OsgDBDataContext db = new OsgDBDataContext();

            // Populates Dictionaries here

            db.Dispose();
        }
    }
}

Is there anything obviously wrong with how I've set this class up that's preventing it from appearing when used via a DLL?

Many thanks

Niall
  • 1,551
  • 4
  • 23
  • 40

2 Answers2

10

Make it public:

public static class GlobalClass
{
   ...
}  

The default accessibility for a class is internal : only visible to code inside the same assembly. That is why it does work when you include it as a .cs in the project.

H H
  • 263,252
  • 30
  • 330
  • 514
  • To read more on default accessibility - http://stackoverflow.com/questions/2521459/what-are-the-default-access-modifiers-in-c?lq=1 – Alexei Levenkov Feb 24 '16 at 20:58
4

Add public to the class, it has no modifier, so it's private within the dll.

René Wolferink
  • 3,558
  • 2
  • 29
  • 43