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.

COM Interop question in .NET 2.0

Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish
Nov 17 '05 #1
26 10622
Vish,

Is it an error in the build process, or the registration process?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.com...
Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with
the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered
for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know
of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish

Nov 17 '05 #2
Vish,

Could it be that ComVisible is false by default now in 2.0? Try the
following example and see if it works.

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
[ComVisible(true)]
Jason Newell
Vish wrote:
Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish

Nov 17 '05 #3

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.com...
Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with
the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered
for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know
of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish


Don't know what exactly you do in the functions that register/unregister the
class, mind to post your code?
Willy.
Nov 17 '05 #4
Hi Jason,

Seems like that did the trick. i am able to build the class after setting
the ComVisible attribute of the class to true. I appreciate your help in this
matter.

Thank You,
Vish
"Jason Newell" wrote:
Vish,

Could it be that ComVisible is false by default now in 2.0? Try the
following example and see if it works.

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
[ComVisible(true)]
Jason Newell
Vish wrote:
Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish

Nov 17 '05 #5
Hi Nicholas,

The error occured while building. But i was able to solve the problem by
setting the ComVisible attribute to true on the class according to Jason's
reply. I think the ComVisible attribute is set to false by default where in
it was true by default in 1.1.

I appreciate your help in this matter.

Thank You,
Vish
"Nicholas Paldino [.NET/C# MVP]" wrote:
Vish,

Is it an error in the build process, or the registration process?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.com...
Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with
the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered
for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know
of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish


Nov 17 '05 #6
Hi Willy,

Jason's suggestion fixed my problem. Looks like the ComVisible property is
false by default in .NET 2.0 where in it was true by default in 1.1. If you
are still interested in looking at the code, let me know. I will post it. I
appreciate you help with this issue.

Thank You,
Vish
"Willy Denoyette [MVP]" wrote:

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.com...
Hi,

I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I also
have two functions in the class to register and unregister the COM with
the
registry. But when i try to build it in VS.NET 2005, i get the following
error "XXX.dll does not contain any types that can be registered for COM
Interop" and "XXX.dll does not contain any types that can be Unregistered
for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody know
of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish


Don't know what exactly you do in the functions that register/unregister the
class, mind to post your code?
Willy.

Nov 17 '05 #7
Can't be the reason as the default for ComVisible is still true.

Willy.

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
Hi Willy,

Jason's suggestion fixed my problem. Looks like the ComVisible property is
false by default in .NET 2.0 where in it was true by default in 1.1. If
you
are still interested in looking at the code, let me know. I will post it.
I
appreciate you help with this issue.

Thank You,
Vish
"Willy Denoyette [MVP]" wrote:

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.com...
> Hi,
>
> I am trying to expose my .NET 2.0 class as a COM type using the
> following
> attributes for the attributes
>
> [ClassInterface(ClassInterfaceType.None)]
> [Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
>
> I have the "Register for COM Interop" build property set to true. I
> also
> have two functions in the class to register and unregister the COM with
> the
> registry. But when i try to build it in VS.NET 2005, i get the
> following
> error "XXX.dll does not contain any types that can be registered for
> COM
> Interop" and "XXX.dll does not contain any types that can be
> Unregistered
> for
> COM Interop". The same code works perfectly in VS.NET 2003. Anybody
> know
> of
> any reasons why this is happeneing or what i am doing wrong?
>
> Thank You,
> Vish


Don't know what exactly you do in the functions that register/unregister
the
class, mind to post your code?
Willy.

Nov 17 '05 #8
Vish,

Willy is correct per documentation:
http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx.

I'd be interested to know why explicitly settings [ComVisible(true)]
fixed the problem. Unfortunately, I don't have 2.0 or I'd test it myself.

Jason Newell
Willy Denoyette [MVP] wrote:
Can't be the reason as the default for ComVisible is still true.

Willy.

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
Hi Willy,

Jason's suggestion fixed my problem. Looks like the ComVisible property is
false by default in .NET 2.0 where in it was true by default in 1.1. If
you
are still interested in looking at the code, let me know. I will post it.
I
appreciate you help with this issue.

Thank You,
Vish
"Willy Denoyette [MVP]" wrote:

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:19**********************************@micro soft.com...

Hi,

I am trying to expose my .NET 2.0 class as a COM type using the
following
attributes for the attributes

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]

I have the "Register for COM Interop" build property set to true. I
also
have two functions in the class to register and unregister the COM with
the
registry. But when i try to build it in VS.NET 2005, i get the
following
error "XXX.dll does not contain any types that can be registered for
COM
Interop" and "XXX.dll does not contain any types that can be
Unregistered
for
COM Interop". The same code works perfectly in VS.NET 2003. Anybody
know
of
any reasons why this is happeneing or what i am doing wrong?

Thank You,
Vish

Don't know what exactly you do in the functions that register/unregister
the
class, mind to post your code?
Willy.


Nov 17 '05 #9

"Jason Newell" <no****@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP15.phx.gbl...
Vish,

Willy is correct per documentation:
http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx.

I'd be interested to know why explicitly settings [ComVisible(true)] fixed
the problem. Unfortunately, I don't have 2.0 or I'd test it myself.

Jason Newell


And not only per documentation ;-), it was the default since version 1.0 and
did not change in v2.0 (that would be a breaking change).
I tested this with v2.0 and I can confirm 'true' is still the default.

Willy.
Nov 17 '05 #10
Yeah I know it's always been default because it's bitten me in the
rear-end a few times ;-). I honestly didn't think that they would have
made a breaking change like that. So the question that still remains,
did setting [ComVisible(true)] really solve the problem or was it
something else?
Jason Newell
Willy Denoyette [MVP] wrote:
"Jason Newell" <no****@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP15.phx.gbl...
Vish,

Willy is correct per documentation:
http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx.

I'd be interested to know why explicitly settings [ComVisible(true)] fixed
the problem. Unfortunately, I don't have 2.0 or I'd test it myself.

Jason Newell

And not only per documentation ;-), it was the default since version 1.0 and
did not change in v2.0 (that would be a breaking change).
I tested this with v2.0 and I can confirm 'true' is still the default.

Willy.

Nov 17 '05 #11

"Jason Newell" <no****@nospam.com> wrote in message
news:eC**************@TK2MSFTNGP11.phx.gbl...
Yeah I know it's always been default because it's bitten me in the
rear-end a few times ;-). I honestly didn't think that they would have
made a breaking change like that. So the question that still remains, did
setting [ComVisible(true)] really solve the problem or was it something
else?
Jason Newell


Pretty sure it was something else (my guess: missing public on the class).

Willy.


Nov 17 '05 #12
Hi,

Ok. I am not sure why but it did fix the issue. Obviously y'all know more on
this subject than i do. But i am posting my code below if y'all are still
interested.

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
[ComVisible(true)]
public sealed class TestTool : BaseCommand
{
private IApplication m_app;

public override void OnCreate(object hook)
{
if (hook != null)
{
if (hook is IMxApplication)
{
m_app = (IApplication)hook;
}
}
}

public override void OnClick()
{
IMxDocument mxDoc = (IMxDocument)m_app.Document;
IActiveView activeView = mxDoc.ActiveView;
activeView.Extent = activeView.FullExtent;
activeView.Refresh();
}

public TestTool()
{
base.m_category = "Vish's Test";
base.m_caption = "Full Extent C#";
base.m_message = "Zooms the display to its full extent";
base.m_toolTip = "Full Extent C#";
base.m_name = "Developer Samples_FullExtent C#";

string[] res = GetType().Assembly.GetManifestResourceNames();
if (res.GetLength(0) > 0)
{
base.m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(res[0]));
}
}

#region Component Category Registration

[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(String regKey)
{
MxCommands.Register(regKey);
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(String regKey)
{
MxCommands.Unregister(regKey);
}

#endregion
}






"Willy Denoyette [MVP]" wrote:

"Jason Newell" <no****@nospam.com> wrote in message
news:eC**************@TK2MSFTNGP11.phx.gbl...
Yeah I know it's always been default because it's bitten me in the
rear-end a few times ;-). I honestly didn't think that they would have
made a breaking change like that. So the question that still remains, did
setting [ComVisible(true)] really solve the problem or was it something
else?
Jason Newell


Pretty sure it was something else (my guess: missing public on the class).

Willy.


Nov 17 '05 #13
Sorry, but this is not a complete sample (missing BaseCommand), so there is
lttle I can do with it, but trust me [ComVisible(true)] IS the default.

I'm also not entirely clear on the purpose is of this class for a COM
client, true, this object creatable from COM clients, but none of it's
methods are callable.
Willy.

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hi,

Ok. I am not sure why but it did fix the issue. Obviously y'all know more
on
this subject than i do. But i am posting my code below if y'all are still
interested.

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
[ComVisible(true)]
public sealed class TestTool : BaseCommand
{
private IApplication m_app;

public override void OnCreate(object hook)
{
if (hook != null)
{
if (hook is IMxApplication)
{
m_app = (IApplication)hook;
}
}
}

public override void OnClick()
{
IMxDocument mxDoc = (IMxDocument)m_app.Document;
IActiveView activeView = mxDoc.ActiveView;
activeView.Extent = activeView.FullExtent;
activeView.Refresh();
}

public TestTool()
{
base.m_category = "Vish's Test";
base.m_caption = "Full Extent C#";
base.m_message = "Zooms the display to its full extent";
base.m_toolTip = "Full Extent C#";
base.m_name = "Developer Samples_FullExtent C#";

string[] res = GetType().Assembly.GetManifestResourceNames();
if (res.GetLength(0) > 0)
{
base.m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(res[0]));
}
}

#region Component Category Registration

[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(String regKey)
{
MxCommands.Register(regKey);
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(String regKey)
{
MxCommands.Unregister(regKey);
}

#endregion
}






"Willy Denoyette [MVP]" wrote:

"Jason Newell" <no****@nospam.com> wrote in message
news:eC**************@TK2MSFTNGP11.phx.gbl...
> Yeah I know it's always been default because it's bitten me in the
> rear-end a few times ;-). I honestly didn't think that they would have
> made a breaking change like that. So the question that still remains,
> did
> setting [ComVisible(true)] really solve the problem or was it something
> else?
>
>
> Jason Newell
>
>


Pretty sure it was something else (my guess: missing public on the
class).

Willy.


Nov 17 '05 #14
Hi Willy,

I wrote this class as an added tool for ESRI's ArcMap Software. The
BaseCommand class is part of their ArcObjects pacakage. So i will not be
provide you with that class. Anyway the the functions of the class below was
called and successfully executed from ArcMap which is completely built on
COM. Anyway that is not to say that you are write about what you are saying.
I just maybe it will help m eunderstand whats happeneing better. I class
below successfully created a new toolbar button and executed on click. Please
let me know what you think.

-Vish


"Willy Denoyette [MVP]" wrote:
Sorry, but this is not a complete sample (missing BaseCommand), so there is
lttle I can do with it, but trust me [ComVisible(true)] IS the default.

I'm also not entirely clear on the purpose is of this class for a COM
client, true, this object creatable from COM clients, but none of it's
methods are callable.
Willy.

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hi,

Ok. I am not sure why but it did fix the issue. Obviously y'all know more
on
this subject than i do. But i am posting my code below if y'all are still
interested.

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
[ComVisible(true)]
public sealed class TestTool : BaseCommand
{
private IApplication m_app;

public override void OnCreate(object hook)
{
if (hook != null)
{
if (hook is IMxApplication)
{
m_app = (IApplication)hook;
}
}
}

public override void OnClick()
{
IMxDocument mxDoc = (IMxDocument)m_app.Document;
IActiveView activeView = mxDoc.ActiveView;
activeView.Extent = activeView.FullExtent;
activeView.Refresh();
}

public TestTool()
{
base.m_category = "Vish's Test";
base.m_caption = "Full Extent C#";
base.m_message = "Zooms the display to its full extent";
base.m_toolTip = "Full Extent C#";
base.m_name = "Developer Samples_FullExtent C#";

string[] res = GetType().Assembly.GetManifestResourceNames();
if (res.GetLength(0) > 0)
{
base.m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(res[0]));
}
}

#region Component Category Registration

[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(String regKey)
{
MxCommands.Register(regKey);
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(String regKey)
{
MxCommands.Unregister(regKey);
}

#endregion
}






"Willy Denoyette [MVP]" wrote:

"Jason Newell" <no****@nospam.com> wrote in message
news:eC**************@TK2MSFTNGP11.phx.gbl...
> Yeah I know it's always been default because it's bitten me in the
> rear-end a few times ;-). I honestly didn't think that they would have
> made a breaking change like that. So the question that still remains,
> did
> setting [ComVisible(true)] really solve the problem or was it something
> else?
>
>
> Jason Newell
>
>

Pretty sure it was something else (my guess: missing public on the
class).

Willy.



Nov 17 '05 #15
Hi,

I have the same problem. If I put [ComVisible(true)] on my class and
methods, it compiles, but I can't use the methods.

As an experiment I created a default Class Library, checked the
"Register for COM interop" -button, and I got the same error message:
"Com_test.dll" does not contain any types that can be registered for
COM Interop.

/Erik

Nov 17 '05 #16

"Erik" <er*************@bredband.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi,

I have the same problem. If I put [ComVisible(true)] on my class and
methods, it compiles, but I can't use the methods.

As an experiment I created a default Class Library, checked the
"Register for COM interop" -button, and I got the same error message:
"Com_test.dll" does not contain any types that can be registered for
COM Interop.

/Erik


Please post your class. Note that this has nothing to do with the ComVisible
attribute (which is definately true by default).

Willy.
Nov 17 '05 #17
In my experiment i created an empty class library, resulting in the
following code.

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

namespace Com_test
{
public class Class1
{
}
}

Shouldn't it compile without an error, even with "Register for COM
interop" checked?

Nov 17 '05 #18

"Erik" <er*************@bredband.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
In my experiment i created an empty class library, resulting in the
following code.

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

namespace Com_test
{
public class Class1
{
}
}

Shouldn't it compile without an error, even with "Register for COM
interop" checked?


This class will compile but cannot be registered for COM interop as it
doesn't have an explicit public empty constructor .

this ...
public class Class1
{
public Class1(){}
}

will do.

Willy.
Nov 17 '05 #19
Hi Willy,

Since the class i had created did have a constructor explicitly defined, why
do you think i wasn't able to compile my class in 2.0

Thank You,
Vish
"Willy Denoyette [MVP]" wrote:

"Erik" <er*************@bredband.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
In my experiment i created an empty class library, resulting in the
following code.

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

namespace Com_test
{
public class Class1
{
}
}

Shouldn't it compile without an error, even with "Register for COM
interop" checked?


This class will compile but cannot be registered for COM interop as it
doesn't have an explicit public empty constructor .

this ...
public class Class1
{
public Class1(){}
}

will do.

Willy.

Nov 17 '05 #20
Thank you for your answer, but I'm afraid that didn't help. Now the
code looks like this:

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

namespace Com_test
{
public class Class1
{
public Class1() { }
}
}

but it still cannot be registered for COM interop.

Nov 17 '05 #21

"Erik" <er*************@bredband.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Thank you for your answer, but I'm afraid that didn't help. Now the
code looks like this:

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

namespace Com_test
{
public class Class1
{
public Class1() { }
}
}

but it still cannot be registered for COM interop.


It should, what error are you getting?

The simplest way to test this is compile the file from the command line
using:

csc /t:library filename.cs
and register with:
regasm /codebase /tlb filename.dll
unregister with:
regasm /unregister /tlb filename.dll

Willy.
Nov 17 '05 #22
You said you couldn't register, now you are teling me you could't compile!
A C# class needs to obey a number of rules (imposed by COM), one of the is
a default public construcor, but there are others.
A public constructor is in general all you need to be able to create an
instance, that doesn't mean that methods are callable. As I said your class
can be instantiated, but your methods are not callable from a native COM
client itself, the fact it works in your case is because you methods
OnCreate and OnClick are not called from COM, they are called from the
container (they are event handlers right?) .
Willy.

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
Hi Willy,

Since the class i had created did have a constructor explicitly defined,
why
do you think i wasn't able to compile my class in 2.0

Thank You,
Vish
"Willy Denoyette [MVP]" wrote:

"Erik" <er*************@bredband.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
> In my experiment i created an empty class library, resulting in the
> following code.
>
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> namespace Com_test
> {
> public class Class1
> {
> }
> }
>
> Shouldn't it compile without an error, even with "Register for COM
> interop" checked?
>


This class will compile but cannot be registered for COM interop as it
doesn't have an explicit public empty constructor .

this ...
public class Class1
{
public Class1(){}
}

will do.

Willy.

Nov 17 '05 #23
Hi Willy,

Yes, i wasnt able to compile. I am sorry if i had misrepresentd in
previously. Also my OnCreate and OnClick functions are in fact getting called
by event handlers. Can you let me know where i can read up on the rules my c#
class needs to foolow in order to be callable from COM.

Thank You,
Vish
"Willy Denoyette [MVP]" wrote:

"Erik" <er*************@bredband.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Thank you for your answer, but I'm afraid that didn't help. Now the
code looks like this:

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

namespace Com_test
{
public class Class1
{
public Class1() { }
}
}

but it still cannot be registered for COM interop.


It should, what error are you getting?

The simplest way to test this is compile the file from the command line
using:

csc /t:library filename.cs
and register with:
regasm /codebase /tlb filename.dll
unregister with:
regasm /unregister /tlb filename.dll

Willy.

Nov 17 '05 #24
I hate dredging this up as its so old, but thought i'd clear this up. After
spending the past 3 days trying everything possible to get my C# code to work
in COM, i almost gave up until seeing this post.

To put it bluntly, the documentation is wrong.

The code i was using in 1.1 DID NOT WORK in 2.0. Simple test case below:

---------- BEGIN ITVTest.cs ----------
using System;
using System.Text;
using System.Runtime.InteropServices;

namespace comitvtest
{
[Guid("3A8E1A9D-206E-48cb-BD4F-0FE6D3155CDF")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class ITVTest : IITVTest
{
public ITVTest()
{
throw new System.NotImplementedException();
}

public int GetCurrentHour()
{
return System.DateTime.Now.Hour;
}
}
}

---------- END ITVTest.cs ----------
---------- BEGIN IITVTest.cs ----------
using System;
using System.Runtime.InteropServices;
namespace comitvtest
{
[Guid("770A5441-1B1D-4847-91B5-B84EDDC1B647")]
interface IITVTest
{
int GetCurrentHour();
}
}
---------- END IITVTest.cs ----------
--- Project Setup ---
Goto Project -> Properties
Click the "Build" tab.
Select the Register for COM Interop option

Click the "Signing" tab.
Select "Sign the Assembly", from the file name select "<new>" give it a name
i used KeyPairing.snk with NO password
Build project
start -> run: cmd

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

H:\>c:

C:\>cd projects\com.itv.test

C:\Projects\com.itv.test\bin\Release>tlbexp com.itv.test.dll
Microsoft (R) .NET Framework Assembly to Type Library Converter 2.0.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

Assembly exported to 'C:\Projects\com.itv.test\bin\Release\com.itv.test .tlb'

C:\Projects\com.itv.test\bin\Release>regasm com.itv.test.dll
/tlb:com.itv.test.t
lb
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Assembly exported to
'C:\Projects\com.itv.test\bin\Release\com.itv.test .tlb', an
d the type library was registered successfully

--- Visual Basic 6 Test ---
Create new Standard EXE project
Goto to Project menu, select References
Find the com assembly in references list (com_itv_test), select, and hit OK
View the object browser
Types are visible here. (can also do the same with with Visual FoxPro's
Class Explorer and open the TLB file.)
--- The Proof ---
Now try it without the ComVisible attribute.
- Mark Harris

C:\Projects\com.itv.test>cd bin/release
"Willy Denoyette [MVP]" wrote:
Sorry, but this is not a complete sample (missing BaseCommand), so there is
lttle I can do with it, but trust me [ComVisible(true)] IS the default.

I'm also not entirely clear on the purpose is of this class for a COM
client, true, this object creatable from COM clients, but none of it's
methods are callable.
Willy.

"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hi,

Ok. I am not sure why but it did fix the issue. Obviously y'all know more
on
this subject than i do. But i am posting my code below if y'all are still
interested.

[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
[ComVisible(true)]
public sealed class TestTool : BaseCommand
{
private IApplication m_app;

public override void OnCreate(object hook)
{
if (hook != null)
{
if (hook is IMxApplication)
{
m_app = (IApplication)hook;
}
}
}

public override void OnClick()
{
IMxDocument mxDoc = (IMxDocument)m_app.Document;
IActiveView activeView = mxDoc.ActiveView;
activeView.Extent = activeView.FullExtent;
activeView.Refresh();
}

public TestTool()
{
base.m_category = "Vish's Test";
base.m_caption = "Full Extent C#";
base.m_message = "Zooms the display to its full extent";
base.m_toolTip = "Full Extent C#";
base.m_name = "Developer Samples_FullExtent C#";

string[] res = GetType().Assembly.GetManifestResourceNames();
if (res.GetLength(0) > 0)
{
base.m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(res[0]));
}
}

#region Component Category Registration

[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(String regKey)
{
MxCommands.Register(regKey);
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(String regKey)
{
MxCommands.Unregister(regKey);
}

#endregion
}






"Willy Denoyette [MVP]" wrote:

"Jason Newell" <no****@nospam.com> wrote in message
news:eC**************@TK2MSFTNGP11.phx.gbl...
> Yeah I know it's always been default because it's bitten me in the
> rear-end a few times ;-). I honestly didn't think that they would have
> made a breaking change like that. So the question that still remains,
> did
> setting [ComVisible(true)] really solve the problem or was it something
> else?
>
>
> Jason Newell
>
>

Pretty sure it was something else (my guess: missing public on the
class).

Willy.



Jan 25 '06 #25
The default ComVisible attribute value did not change, what did change in
VS2005 was the AssemblyInfo.cs file which now contains [assembly:
ComVisible(false)]. But, the default (that is whan the attribute is not
specified) is still true.
Willy.

"Mark Harris" <Mark Ha****@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
|I hate dredging this up as its so old, but thought i'd clear this up. After
| spending the past 3 days trying everything possible to get my C# code to
work
| in COM, i almost gave up until seeing this post.
|
| To put it bluntly, the documentation is wrong.
|
| The code i was using in 1.1 DID NOT WORK in 2.0. Simple test case below:
|
| ---------- BEGIN ITVTest.cs ----------
| using System;
| using System.Text;
| using System.Runtime.InteropServices;
|
| namespace comitvtest
| {
| [Guid("3A8E1A9D-206E-48cb-BD4F-0FE6D3155CDF")]
| [ClassInterface(ClassInterfaceType.AutoDual)]
| [ComVisible(true)]
| public class ITVTest : IITVTest
| {
| public ITVTest()
| {
| throw new System.NotImplementedException();
| }
|
| public int GetCurrentHour()
| {
| return System.DateTime.Now.Hour;
| }
| }
| }
|
| ---------- END ITVTest.cs ----------
|
|
| ---------- BEGIN IITVTest.cs ----------
| using System;
| using System.Runtime.InteropServices;
| namespace comitvtest
| {
| [Guid("770A5441-1B1D-4847-91B5-B84EDDC1B647")]
| interface IITVTest
| {
| int GetCurrentHour();
| }
| }
| ---------- END IITVTest.cs ----------
|
|
| --- Project Setup ---
| Goto Project -> Properties
| Click the "Build" tab.
| Select the Register for COM Interop option
|
| Click the "Signing" tab.
| Select "Sign the Assembly", from the file name select "<new>" give it a
name
| i used KeyPairing.snk with NO password
|
|
| Build project
| start -> run: cmd
|
| Microsoft Windows XP [Version 5.1.2600]
| (C) Copyright 1985-2001 Microsoft Corp.
|
| H:\>c:
|
| C:\>cd projects\com.itv.test
|
| C:\Projects\com.itv.test\bin\Release>tlbexp com.itv.test.dll
| Microsoft (R) .NET Framework Assembly to Type Library Converter
2.0.50727.42
| Copyright (C) Microsoft Corporation. All rights reserved.
|
| Assembly exported to
'C:\Projects\com.itv.test\bin\Release\com.itv.test .tlb'
|
| C:\Projects\com.itv.test\bin\Release>regasm com.itv.test.dll
| /tlb:com.itv.test.t
| lb
| Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
| Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
|
| Assembly exported to
| 'C:\Projects\com.itv.test\bin\Release\com.itv.test .tlb', an
| d the type library was registered successfully
|
| --- Visual Basic 6 Test ---
| Create new Standard EXE project
| Goto to Project menu, select References
| Find the com assembly in references list (com_itv_test), select, and hit
OK
| View the object browser
| Types are visible here. (can also do the same with with Visual FoxPro's
| Class Explorer and open the TLB file.)
|
|
| --- The Proof ---
| Now try it without the ComVisible attribute.
|
|
| - Mark Harris
|
|
|
| C:\Projects\com.itv.test>cd bin/release
| "Willy Denoyette [MVP]" wrote:
|
| > Sorry, but this is not a complete sample (missing BaseCommand), so there
is
| > lttle I can do with it, but trust me [ComVisible(true)] IS the default.
| >
| > I'm also not entirely clear on the purpose is of this class for a COM
| > client, true, this object creatable from COM clients, but none of it's
| > methods are callable.
| >
| >
| > Willy.
| >
| > "Vish" <Vi**@discussions.microsoft.com> wrote in message
| > news:EB**********************************@microsof t.com...
| > > Hi,
| > >
| > > Ok. I am not sure why but it did fix the issue. Obviously y'all know
more
| > > on
| > > this subject than i do. But i am posting my code below if y'all are
still
| > > interested.
| > >
| > > [ClassInterface(ClassInterfaceType.None)]
| > > [Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
| > > [ComVisible(true)]
| > > public sealed class TestTool : BaseCommand
| > > {
| > > private IApplication m_app;
| > >
| > > public override void OnCreate(object hook)
| > > {
| > > if (hook != null)
| > > {
| > > if (hook is IMxApplication)
| > > {
| > > m_app = (IApplication)hook;
| > > }
| > > }
| > > }
| > >
| > > public override void OnClick()
| > > {
| > > IMxDocument mxDoc = (IMxDocument)m_app.Document;
| > > IActiveView activeView = mxDoc.ActiveView;
| > > activeView.Extent = activeView.FullExtent;
| > > activeView.Refresh();
| > > }
| > >
| > > public TestTool()
| > > {
| > > base.m_category = "Vish's Test";
| > > base.m_caption = "Full Extent C#";
| > > base.m_message = "Zooms the display to its full extent";
| > > base.m_toolTip = "Full Extent C#";
| > > base.m_name = "Developer Samples_FullExtent C#";
| > >
| > > string[] res =
GetType().Assembly.GetManifestResourceNames();
| > > if (res.GetLength(0) > 0)
| > > {
| > > base.m_bitmap = new
| > >
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(res[0]));
| > > }
| > > }
| > >
| > > #region Component Category Registration
| > >
| > > [ComRegisterFunction()]
| > > [ComVisible(false)]
| > > static void RegisterFunction(String regKey)
| > > {
| > > MxCommands.Register(regKey);
| > > }
| > >
| > > [ComUnregisterFunction()]
| > > [ComVisible(false)]
| > > static void UnregisterFunction(String regKey)
| > > {
| > > MxCommands.Unregister(regKey);
| > > }
| > >
| > > #endregion
| > > }
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > > "Willy Denoyette [MVP]" wrote:
| > >
| > >>
| > >> "Jason Newell" <no****@nospam.com> wrote in message
| > >> news:eC**************@TK2MSFTNGP11.phx.gbl...
| > >> > Yeah I know it's always been default because it's bitten me in the
| > >> > rear-end a few times ;-). I honestly didn't think that they would
have
| > >> > made a breaking change like that. So the question that still
remains,
| > >> > did
| > >> > setting [ComVisible(true)] really solve the problem or was it
something
| > >> > else?
| > >> >
| > >> >
| > >> > Jason Newell
| > >> >
| > >> >
| > >>
| > >> Pretty sure it was something else (my guess: missing public on the
| > >> class).
| > >>
| > >> Willy.
| > >>
| > >>
| > >>
| > >>
| > >>
| >
| >
| >
Jan 25 '06 #26


Jason, if you could e-mail me at my e-mail address that would be
wonderful.
Sara

*** Sent via Developersdex http://www.developersdex.com ***
Feb 4 '06 #27

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

Similar topics

0
by: roy | last post by:
I try to call com written in VB 6.0. When I use VS.net Studio to do the debuging, some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation'...
0
by: roy | last post by:
I try to call com written in VB 6.0., some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation' Application....
0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
0
by: lacour | last post by:
I can't seem to figure out the difference between adding a COM dll reference in VS2003 and by using TLBIMP. I have a COM dll that references another COM dll, and I want the syntax of my...
1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
0
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.