473,320 Members | 2,052 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,320 software developers and data experts.

Namespace and COM library nme conflict

Hi Folks,

I am coming up to speed with C# and I have run into an interesting
issue.

I have an old VB COM library that I need to access with a ProgId ==
'xyz'

I also have a C# class that is in a namespace like this:
"A.xyz.abc..."

I have added the COM library as a reference, but when I try to
reference out of the COM library, the compiler and Intellisense don't
see it:

xyz.objectname Temp = new xyz.objectname();

This fails, because it is looking in the namespace a.xyz for
objectname, not in the COM object.

Is there a way I can explicitly reference the object in the COM
library, or is there a way to alias the COM library?

Thanks!

Jami Bradley
reverse 2nd level domain: jb******@isa-og.com
Nov 15 '05 #1
8 1431
James,

You should be able to alias the namespace like this:

// Alias the A.xyz namespace.
using Axyz = A.xyz;

Then, you should be able to use:

// The class in A.xyz.
Axyz.abc pobj1 = new Axyz.abc;

// The com class.
xyz.objectname pobj2 = new xyz.objectname();

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James Bradley" <jb******@isa-og.com> wrote in message
news:cg********************************@4ax.com...
Hi Folks,

I am coming up to speed with C# and I have run into an interesting
issue.

I have an old VB COM library that I need to access with a ProgId ==
'xyz'

I also have a C# class that is in a namespace like this:
"A.xyz.abc..."

I have added the COM library as a reference, but when I try to
reference out of the COM library, the compiler and Intellisense don't
see it:

xyz.objectname Temp = new xyz.objectname();

This fails, because it is looking in the namespace a.xyz for
objectname, not in the COM object.

Is there a way I can explicitly reference the object in the COM
library, or is there a way to alias the COM library?

Thanks!

Jami Bradley
reverse 2nd level domain: jb******@isa-og.com

Nov 15 '05 #2
I saw that option in the using statement and thought that it would
work. Unfortunately, my problem is that I am *in* the namespace
A.xyz.abc, so I don't think I can alias my own namespace.

It looks something like this:

namespace A.xyz.abc
{
public class def
{
public void func()
{
// This statement attempts to access A.xyz.objectname:
xyz.objectname pobj2 = new xyz.objectname();
}
}
}

On Tue, 9 Dec 2003 13:15:49 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

You should be able to alias the namespace like this:

// Alias the A.xyz namespace.
using Axyz = A.xyz;

Then, you should be able to use:

// The class in A.xyz.
Axyz.abc pobj1 = new Axyz.abc;

// The com class.
xyz.objectname pobj2 = new xyz.objectname();

Hope this helps.


Nov 15 '05 #3
James,

You can try to alias each object that you want to use, but I can see how
this could be unwieldy. Also, you could create the interop assembly
yourself using the TLBIMP program and then use the /namespace option to
indicate a different namespace which doesn't conflict.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James Bradley" <jb******@isa-og.com> wrote in message
news:ag********************************@4ax.com...
I saw that option in the using statement and thought that it would
work. Unfortunately, my problem is that I am *in* the namespace
A.xyz.abc, so I don't think I can alias my own namespace.

It looks something like this:

namespace A.xyz.abc
{
public class def
{
public void func()
{
// This statement attempts to access A.xyz.objectname:
xyz.objectname pobj2 = new xyz.objectname();
}
}
}

On Tue, 9 Dec 2003 13:15:49 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

You should be able to alias the namespace like this:

// Alias the A.xyz namespace.
using Axyz = A.xyz;

Then, you should be able to use:

// The class in A.xyz.
Axyz.abc pobj1 = new Axyz.abc;

// The com class.
xyz.objectname pobj2 = new xyz.objectname();

Hope this helps.

Nov 15 '05 #4
Thanks! I'll look into tlbimp and those options - I haven't done that
process manually with vs.net yet :-)

Is it possible to alias a COM object? For example, if I have
xyz.object1 in my COM library, can I use some alias to access that? I
thought the aliasing was only for the namespaces. I only have 3 or 4
objects like this, so individual aliasing is not all that bad.

Jami
On Tue, 9 Dec 2003 13:40:17 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

You can try to alias each object that you want to use, but I can see how
this could be unwieldy. Also, you could create the interop assembly
yourself using the TLBIMP program and then use the /namespace option to
indicate a different namespace which doesn't conflict.


Nov 15 '05 #5
James,

Yes, you can alias individual types, like so:

// Alias the xyz.object type.
using MyComObject = xyz.object;

This will alias the one type with MyComObject. It ^should^ work, but
being in the namespace, I think you will still have problems (call it a
hunch). However, it wouldn't be so hard to try.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James Bradley" <jb******@isa-og.com> wrote in message
news:p1********************************@4ax.com...
Thanks! I'll look into tlbimp and those options - I haven't done that
process manually with vs.net yet :-)

Is it possible to alias a COM object? For example, if I have
xyz.object1 in my COM library, can I use some alias to access that? I
thought the aliasing was only for the namespaces. I only have 3 or 4
objects like this, so individual aliasing is not all that bad.

Jami
On Tue, 9 Dec 2003 13:40:17 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

You can try to alias each object that you want to use, but I can see howthis could be unwieldy. Also, you could create the interop assembly
yourself using the TLBIMP program and then use the /namespace option to
indicate a different namespace which doesn't conflict.

Nov 15 '05 #6
I tried aliasing the COM object and it worked great! Because the
using is outside of the namespace declaration, it had no trouble
finidng the COM object.

Here is what I ended up using:
using MyComLibrary = xyz;

and now I can access it directly:
MyComLibrary.object pObj = new MyComLibrary.object();

Thank you for all your help!

Jami

On Tue, 9 Dec 2003 13:55:47 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

Yes, you can alias individual types, like so:

// Alias the xyz.object type.
using MyComObject = xyz.object;

This will alias the one type with MyComObject. It ^should^ work, but
being in the namespace, I think you will still have problems (call it a
hunch). However, it wouldn't be so hard to try.


Nov 15 '05 #7
James,
In addition to Nicholas's suggestions:

Have you tried to create an alias for the COM namespace before you enter the
A namespace?

using xyzcom = xyz
namespace A.xyz.abc
{ xyzcom.objectname pobj2 = new xyzcom.objectname();
Hope this helps
Jay

"James Bradley" <jb******@isa-og.com> wrote in message
news:ag********************************@4ax.com... I saw that option in the using statement and thought that it would
work. Unfortunately, my problem is that I am *in* the namespace
A.xyz.abc, so I don't think I can alias my own namespace.

It looks something like this:

namespace A.xyz.abc
{
public class def
{
public void func()
{
// This statement attempts to access A.xyz.objectname:
xyz.objectname pobj2 = new xyz.objectname();
}
}
}

On Tue, 9 Dec 2003 13:15:49 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

You should be able to alias the namespace like this:

// Alias the A.xyz namespace.
using Axyz = A.xyz;

Then, you should be able to use:

// The class in A.xyz.
Axyz.abc pobj1 = new Axyz.abc;

// The com class.
xyz.objectname pobj2 = new xyz.objectname();

Hope this helps.

Nov 15 '05 #8
I tried aliasing the COM object and it worked great! Because the
using is outside of the namespace declaration, it had no trouble
finidng the COM object.

Here is what I ended up using:
using MyComLibrary = xyz;

and now I can access it directly:
MyComLibrary.object pObj = new MyComLibrary.object();

Thank you for all your help!

Jami

On Tue, 9 Dec 2003 13:55:47 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
James,

Yes, you can alias individual types, like so:

// Alias the xyz.object type.
using MyComObject = xyz.object;

This will alias the one type with MyComObject. It ^should^ work, but
being in the namespace, I think you will still have problems (call it a
hunch). However, it wouldn't be so hard to try.


Nov 15 '05 #9

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

Similar topics

1
by: Wayne | last post by:
I have the following Namesapces (only for example, would not name them this way in production code) Wayne.Test.Data Wayne.Test.BR With in Wayne.Test.Data name space I have the following...
4
by: yuliy | last post by:
Hello gurus, I stuck in following: how can I do forward declaration if the forward declared class is in some namespace? something like // header class std::string; // approach#1
11
by: alex sparsky | last post by:
I have a rather unique problem that I need some advice on. I have multiple c# controls that need to make use of a common namespace. So when I go to include both controls that make use of that...
2
by: Jéjé | last post by:
Hi, I'm using the ADOMD.Net 9 in my web site + a third party web control which used the ADOMD.Net 8.0. Everytime I compile my web site in VS 2005, a referecne to the 8.0 library is added this...
12
by: bgeneto | last post by:
I know that it's a very basic question, but I can't figure out or find an answer to why do we have to specify a namespace, like this #include<string> using namespace std; when using the...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: Frederick Gotham | last post by:
Back in the day, if you wanted a function to be self-contained within a translation unit, you defined the function as "static". If there were an external linkage function by the same name...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
4
by: Andrew | last post by:
I am having an interesting namespace conflict. When we use a third party lib we create a company assembly for any descending classes to go in. I have simplified the problem into the example...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.