Is there a way to reference a certain class/interface/… by enclosing it with its namespace rather than a using directive “using namespace_name”?

StackOverflow https://stackoverflow.com/questions/4712712

Question

Is there a way to reference a certain class/interface/... by enclosing it with its namespace rather than a using directive "using namespace_name" ?!

As, I'm working on a website, which uses SAP .NET connector. I already added a reference for connector ddl, and while referencing its namespace "using namespace_name", or set class namespace to another one rather than connector namespace,

I got error regarding connector classes with that error message "The type or namespace couldn't be found, are you missing a using directive or an assembly reference?".

But while changing namespace name to connector namespace, everything is going well?!

// Set namespace to be IDestinationConfiguration interface namespace.
// Using this, everything is going well.
namespace SAP.Middleware.Connector
{
    public class ConnectorConfiguration : IDestinationConfiguration
    {
    }
}

// Using that way; it's not working, and got an error regarding IDestinationConfiguration even it belongs to refernced namespace.
using SAP.Middleware.Connector;

public class ConnectorConfiguration : IDestinationConfiguration
{
}

So, connector types forced me to set namespace of class to their namespace!

Is this possible? If so, how?

Was it helpful?

Solution

Is this what you are after?

public class ConnectorConfiguration: SAP.Middleware.Connection.IDestinationConfiguration
{

}

You can write all your code without usings if you like, you just need to use the fully qualified namespace name for every class/interface where the using isn't used.

If you try this:

using SAPTEST = SAP.Middleware.Connection;
namespace TestNamespace 
{
   public class ConnectorConfiguration: SAPTEST.IDestinationConfiguration
   {
   }
}

If that works, but it doesn't work if you remove SAPTEST, then IDestinationConfiguration must be declared in another namespace too.

OTHER TIPS

I ran into this too and couldn't figure it out until I finally found the answer on a post at http://forums.sdn.sap.com/thread.jspa?threadID=1876430, the last line which said:

"Also, make sure your target framework is ".NET v4.0" NOT ".NET v4.0 Client" -- that way you get the System.Web namespace that is required."

My project was targeting 4.0 client target framework. Once I changed it to just .NET Freamework 4.0, all the references worked as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top