简体   繁体   中英

issues with class library using nested name spaces

EDIT: I have a class library that is growing rapidly and I've decided to organize it a little... The class library namespaces are structured like this:

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

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;

namespace ClassLibrary1
{
    namespace FirstNS
    {
        public class Class1
        {
            ReportDocument report = new ReportDocument();

            public static void ShowMe()
            {
                Console.WriteLine("Class1");
            }
        }
    }
    namespace SecondNS
    {
        public class Class2
        {
            public static void ShowMe()
            {
                Console.WriteLine("Class2");
            }
        }
    }
}

It compiles fine. When I try to consume the compiled dll by referencing it in a console application I can reference the namespace with the using directive. However when I try to build the application it says "the type or namespace name 'ClassLibrary1' could not be found...".

I've figured out that taking out the CrystalDecisions assemblies fixes the problem I am just unsure why. - As weird as it sounds somehow the problem relates to having nested namespaces. If I use separate namespaces the problem's gone.

Okay, based on your example and error it sounds like the main application which references your library doesn't have access to the crystal assemblies.

In your main app, add references to crystal OR at the very least put those assemblies in your bin directory. Because the main app can't locate all of the necessary parts for your assembly, it can't use it.

Chris's response made me think about accessible assemblies and I realised what the problem was.

The Crystal assemblies are Framework 2 and the main application was Framework 4. Changing the target framework back to 2 fixed the problem. Equally I assume using Framework 4 Crystal assemblies (if they exist) should solve the problem, too.

PS: I think the error message could be more helpful though... maybe pointing out that a resource is inaccessible rather than the entire class library. :)

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