473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Referencing assemblies

Hi,

I've got a problem with referencing assemblies.

I reference an assembly in my programm; this assembly defines a method
"SayHello" in the class "Hello", namespace "MyNamespace". In my program
I define a method called "SayHello" in a class called "Hello",
namespace "MyNamespace", too. When I try to call the method
"MyNamespace.Hello.SayHello();" the C#-compiler outputs a warning since
it doesn't know whether to call the method defined in my programm or
the method defined in the referenced assembly (it chooses the method
defined in my programm by default, btw.).

With IL (MSIL) I got the possibility to choose myself which method to
call:

//Calls the method defined in my program
call void MyNamespace.Hello::SayHello()

//Calls the method defined in the referenced assembly
call void [externalAssembly] MyNamespace.Hello::SayHello()

Is something similar also possible with C#?

Thanks,
Simon

Jan 16 '06 #1
4 2485
caelis wrote:
I reference an assembly in my programm; this assembly defines a method
"SayHello" in the class "Hello", namespace "MyNamespace". In my program
I define a method called "SayHello" in a class called "Hello",
namespace "MyNamespace", too. When I try to call the method
"MyNamespace.Hello.SayHello();" the C#-compiler outputs a warning since
it doesn't know whether to call the method defined in my programm or
the method defined in the referenced assembly (it chooses the method
defined in my programm by default, btw.). call void MyNamespace.Hello::SayHello() call void [externalAssembly] MyNamespace.Hello::SayHello() Is something similar also possible with C#?


In 2.0, you can specify an alias reference (reference properties, in
VS.2005) so that your externalAssembly might be loaded into the
externalAssembly namespace, and you can say

extern alias externalAssembly;

and then refer to externalAssembly::MyNamespace.Hello::SayHello().

--
<http://www.midnightbeach.com>
Jan 16 '06 #2
Why would you ever want to do this?

Is it possible using an alias with the using directive?

using OtherMyNamespace = MyNamespace

class MyNamespace
{
// and so on and so forth...
}

"caelis" <si********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

I've got a problem with referencing assemblies.

I reference an assembly in my programm; this assembly defines a method
"SayHello" in the class "Hello", namespace "MyNamespace". In my program
I define a method called "SayHello" in a class called "Hello",
namespace "MyNamespace", too. When I try to call the method
"MyNamespace.Hello.SayHello();" the C#-compiler outputs a warning since
it doesn't know whether to call the method defined in my programm or
the method defined in the referenced assembly (it chooses the method
defined in my programm by default, btw.).

With IL (MSIL) I got the possibility to choose myself which method to
call:

//Calls the method defined in my program
call void MyNamespace.Hello::SayHello()

//Calls the method defined in the referenced assembly
call void [externalAssembly] MyNamespace.Hello::SayHello()

Is something similar also possible with C#?

Thanks,
Simon

Jan 16 '06 #3
caelis <si********@gmail.com> wrote:
I've got a problem with referencing assemblies.

I reference an assembly in my programm; this assembly defines a method
"SayHello" in the class "Hello", namespace "MyNamespace". In my program
I define a method called "SayHello" in a class called "Hello",
namespace "MyNamespace", too. When I try to call the method
"MyNamespace.Hello.SayHello();" the C#-compiler outputs a warning since
it doesn't know whether to call the method defined in my programm or
the method defined in the referenced assembly (it chooses the method
defined in my programm by default, btw.).
Well, the first thing to suggest is: don't do that. Even if you can be
explicit about it, it's never going to be a nice thing to do in terms
of readability.
With IL (MSIL) I got the possibility to choose myself which method to
call:

//Calls the method defined in my program
call void MyNamespace.Hello::SayHello()

//Calls the method defined in the referenced assembly
call void [externalAssembly] MyNamespace.Hello::SayHello()

Is something similar also possible with C#?


There is in C# 2.0. You can use use "extern aliases":

extern alias OtherLib;

class Foo
{
...
OtherLib::MyNamespace.Hello.SayHello();
}

You would then compile from the command line with:

csc /r:Otherlib=WhateverTheDllNameIs.dll Foo.cs

However, I don't know off-hand how you do this in VS 2005.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #4
Thanks very much for your answers. "extern alias" is exactly what I was
looking for. Visual C# 2005 even has an "Alias" field in the "Reference
Properties" pane - I overlooked that before.

Bye,
Simon

Jan 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: loretta.stokes | last post by:
I manage our nightly builds for all of our products. Since we have added our .NET assemblies to our nightly build, it has been a learning process. I have come across a couple of situations that I...
12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
16
by: PromisedOyster | last post by:
Hi I have a situation where I want to use circular referencing. I have cut down the example for demonstration purposes. Say we have one executable (main.exe) and two DLLS (A1.dll and A2.dll)....
9
by: Brett Romero | last post by:
Say I have a library (A.dll) with a method that accepts a collection of a specific type. The type is defined in B.dll. In A.dll, I need to loop through this collection and reference fields of...
0
by: Demetri | last post by:
I have a performance question with regards to packaging assemblies and referencing them. First lets say you have created the following assemblies: Company.Framework.dll...
11
by: Jan | last post by:
I'm using the CSharpCodeProvider to buils some assemblies @ runtime which are never saved as files (cp.GenerateInMemory = true;). The generated assemblies are hierachically dependent on each other...
2
by: Jan | last post by:
Regarding my post "CSharpCodeProvider: referencing other generated "InMemory" assembly" 4/27/2006 and the blog from Greg Young http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx I...
5
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
I am experiencing a lot of speed issues on initial app loads where we are referencing 3rd party 1.1 assemblies from 2.0 code. Those 1.1 assemblies reference things like System.Windows.Forms...
1
by: Dave Anson | last post by:
What is the recommended practice for referencing assemblies in a project from other solutions? I am using Visual Studio 2005 Team System. I have several assemblies in another solution which will...
1
by: Tom | last post by:
My unsigned DLL works in my project that references it as long as I set Copy Local = true. Now I have signed the DLL with the sn.exe generated keys but have not yet moved the DLL into the GAC. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.