Newbie Q: DLL class Inaccessible due to protection level.



My goal is to create a C# DLL which I can use in other C# applications.

I have built a simple C# DLL which contains:
namespace MyFunctions
class MyClass
public static int Function1(). . .

I include the DLL as a reference in my target Windows Application project.
I also include the statement
using MyFunctions
I then try to call the function from the DLL using
iRC = MyClass.Function1();
When I try to build the application, I get the error messages:
'MyFunctions.MyClass' is inaccessible due to its protection level.
'MyFunctions.MyClass' does not contain a definition for 'Function1'

Could someone please advise what I am doing wrong? Why is the class /
function inaccessible?



Nicholas Paldino [.NET/C# MVP]


How do you declare MyClass? Is it public, or
private/internal/protected? If you are going to access it outside of the
dll you declare it in, it must be public.



José Joye

If you do not specify a protection level before the class keyword, it is
assumed "protected".
Declaring public class MyClass {...} should solve the problem

- José

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