The default ComVisible attribute value did not change, what did change in
VS2005 was the AssemblyInfo.cs file which now contains [assembly:
ComVisible(fals e)]. But, the default (that is whan the attribute is not
specified) is still true.
Willy.
"Mark Harris" <Mark
Ha****@discussi ons.microsoft.c om> wrote in message
news:DB******** *************** ***********@mic rosoft.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( ClassInterfaceT ype.AutoDual)]
| [ComVisible(true )]
| public class ITVTest : IITVTest
| {
| public ITVTest()
| {
| throw new System.NotImple mentedException ();
| }
|
| 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.it v.test
|
| C:\Projects\com .itv.test\bin\R elease>tlbexp com.itv.test.dl l
| 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\co m.itv.test\bin\ Release\com.itv .test.tlb'
|
| C:\Projects\com .itv.test\bin\R elease>regasm com.itv.test.dl l
| /tlb:com.itv.tes t.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\co m.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**@discussio ns.microsoft.co m> wrote in message
| > news:EB******** *************** ***********@mic rosoft.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( ClassInterfaceT ype.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)h ook;
| > > }
| > > }
| > > }
| > >
| > > public override void OnClick()
| > > {
| > > IMxDocument mxDoc = (IMxDocument)m_ app.Document;
| > > IActiveView activeView = mxDoc.ActiveVie w;
| > > activeView.Exte nt = activeView.Full Extent;
| > > activeView.Refr esh();
| > > }
| > >
| > > 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_FullExt ent C#";
| > >
| > > string[] res =
GetType().Assem bly.GetManifest ResourceNames() ;
| > > if (res.GetLength( 0) > 0)
| > > {
| > > base.m_bitmap = new
| > >
System.Drawing. Bitmap(GetType( ).Assembly.GetM anifestResource Stream(res[0]));
| > > }
| > > }
| > >
| > > #region Component Category Registration
| > >
| > > [ComRegisterFunc tion()]
| > > [ComVisible(fals e)]
| > > static void RegisterFunctio n(String regKey)
| > > {
| > > MxCommands.Regi ster(regKey);
| > > }
| > >
| > > [ComUnregisterFu nction()]
| > > [ComVisible(fals e)]
| > > static void UnregisterFunct ion(String regKey)
| > > {
| > > MxCommands.Unre gister(regKey);
| > > }
| > >
| > > #endregion
| > > }
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > >
| > > "Willy Denoyette [MVP]" wrote:
| > >
| > >>
| > >> "Jason Newell" <no****@nospam. com> wrote in message
| > >> news:eC******** ******@TK2MSFTN GP11.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.
| > >>
| > >>
| > >>
| > >>
| > >>
| >
| >
| >