简体   繁体   中英

Referring a type defined in other project in Visual Studio 2010/C#

I have a Fixed Point type by subclassing Type (refer to this post ). I could build this project name it a.dll.

namespace System
{
public class FixedPointDataType : Type
{
    public Boolean Signed { get; set; }
    public int Width { get; set; }
    public int IntegerWidth { get; set; }
    public FixedPointDataType(Boolean signed = false, int width = 16, int integerWidth = 8)
    {
        Signed = signed;
        Width = width;
        IntegerWidth = integerWidth;
    }
...

I have another project b.dll that uses the System.FixedPointDataType that is in a.dll. After referencing a.dll in project b, when I tried to compile the file abc.cs in project b, I got this error.

Error   2   'System.FixedPointDataType' is inaccessible due to its protection level 
abc.cs

What might be wrong?

ADDED

I needed to add public and give the full name with namespaces - System.FixedPointDataType . I got error even after the modification, but when I rebuilt the whole solution, and the error is removed. Thanks for the comments and answers.

Your class is not declared public ; or it was before you changed your post and rebuilt the project.

But I stand by the earlier comments that you should not subclass Type or add members to namespace System .

If the two projects are in the same solution, make sure you add a reference to the project, not just to the DLL that is the output of the project. If you don't add a reference to the project, VS won't know what order to build your solution in, and you may be referencing outdated versions.

Your other post doesn't tell us what namespace you've used for your FixedPoint class.

I'd suggest you need a Using statement or fully-qualify the type name.

EDIT: Ooh, bad timing on my part!

If the code that you've described above is accurate (sure you're not missing 'public' from the class?), perhaps it's an issue with the fact that you're using the System namespace which, while I have no evidence, might be a special case.

See what happens if you change the namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM