Re: Question about ComRegisterFunctionAttribute...

Steve Johnson <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
"Helper" is not ComVisible.

--
Steve Johnson


On Jan 27, 2008 8:17 PM, Gyorgy Bozoki <[email protected]> wrote:

> Hi all,
>
> I seem to have a problem with ComRegisterFunctionAttribute attribute. Here
> is a bit of sample code:
>
> // Start of sample --------------------
> // --------------------
> // Sample.cs
> // --------------------
> using System;
> using System.Collections.Generic;
> using System.Text;
> using System.Runtime.InteropServices;
> using System.Windows.Forms;
>
> namespace SampleLib
> {
>    public static class Guids
>    {
>        public const string CLSID_TestGuid =
>            "33DE01D3-DC04-4198-AE5D-58B1A36FC122";
>    }
>
>    [Guid ( Guids.CLSID_TestGuid ), ProgId ( "SampleLib.SampleClass" )]
>    [ClassInterface ( ClassInterfaceType.AutoDual )]
>    [ComVisible ( true )]
>    public class SampleClass
>    {
>        public void SomeFunc ()
>        {
>            MessageBox.Show ( "Something" );
>        }
>    }
>
>    public static class Helper
>    {
>        [ComRegisterFunctionAttribute]
>        public static void RegServer ( Type oType )
>        {
>            MessageBox.Show ( "Register" );
>        }
>
>        [ComUnregisterFunctionAttribute]
>        public static void UnregServer ( Type oType )
>        {
>            MessageBox.Show ( "Unregister" );
>        }
>    }
> }
>
> // --------------------
> // AssemblyInfo.cs
> // --------------------
> using System.Reflection;
> using System.Runtime.CompilerServices;
> using System.Runtime.InteropServices;
> using System.Security.Permissions;
>
> [assembly: AssemblyTitle ( "SampleLib" )]
> [assembly: AssemblyDescription ( "" )]
> [assembly: AssemblyConfiguration ( "" )]
> [assembly: AssemblyCompany ( "" )]
> [assembly: AssemblyProduct ( "SampleLib" )]
> [assembly: AssemblyCopyright ( "Copyright C  2008" )]
> [assembly: AssemblyTrademark ( "" )]
> [assembly: AssemblyCulture ( "" )]
> [assembly: RegistryPermissionAttribute ( SecurityAction.RequestMinimum,
>        ViewAndModify = "HKEY_LOCAL_MACHINE" )]
>
> [assembly: ComVisible ( false )]
> [assembly: Guid ( "86077dae-29ae-4905-855b-798aaa7be210" )]
> [assembly: AssemblyVersion ( "1.0.0.0" )]
> [assembly: AssemblyFileVersion ( "1.0.0.0" )]
> // End of sample --------------------
>
> The build output is a single DLL, SampleLib.dll.
>
> It seems that the above code builds without any errors but when I try to
> register the resulting DLL using regasm.exe, the RegServer and/or
> UnregServer function is never called. According to the documentation,
> these
> functions can be public or private (or internal), but they must be static
> and take a single Type parameter to be called during registration for COM.
>
> Is there anything I need to do to make this working? I'm using .Net 2.0with
> SP1 and I have this same behavior on several computers. Any advice would
> be
> greatly appreciated.
>
> Thanks,
> Gyorgy Bozoki
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.