none
VBA Excel call to c# dll via Visual Studio 2012 RRS feed

  • Question

  • I have created a dll lib via the following:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace VBAprocs
    {
        public class fileSys
        {
            public string getDirectories()
            {
                return "Directory A";
            }
        }
    }

    using the COM interop facilities  ie checking both the "Make assembly COM-Visible" and the "Register for COM InterOp" boxes on the project property pages [Visual Studio 2012 Express Edition]
    However when I try and build the class library, I get the following message regardless of the fact that I am executing from an account with administrative privileges. What do I need to do to get the dll library registered?

    "Cannot register assembly "D:\VS_Development\VBAprocs\VBAprocs\bin\Debug\VBAprocs.dll"  - access denied. Please make sure you're running the application as Administrator. Access to the registry key 'HKEY_CLASSES_ROOT\VBAprocs.fileSys' is denied."

    Wednesday, September 24, 2014 1:51 AM

Answers

  • Hello CatFelix,

    It seems that you are trying to create a COM Interop via C#, as the error message says, have you run the Visio Studio as the administrator role? If not, you need to do that.

    And to register a C# class to a COM class, we need to add some attributes above this class, here I modified your provided class, you could try with it.

    [ComVisible(true)]
    
        [ClassInterface(ClassInterfaceType.AutoDual)]
    
        [Guid("1224B067-D0A7-4210-A3CC-C78F21BBF146")]
    
        public class fileSys
    
        {
    
            public string getDirectories()
    
            {
    
                return "Directory A";
    
            }
    
        }
    

    If this does not work for you, please let me know.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by CatFelix Thursday, September 25, 2014 6:06 AM
    Thursday, September 25, 2014 3:00 AM
    Moderator

All replies

  • Hello CatFelix,

    It seems that you are trying to create a COM Interop via C#, as the error message says, have you run the Visio Studio as the administrator role? If not, you need to do that.

    And to register a C# class to a COM class, we need to add some attributes above this class, here I modified your provided class, you could try with it.

    [ComVisible(true)]
    
        [ClassInterface(ClassInterfaceType.AutoDual)]
    
        [Guid("1224B067-D0A7-4210-A3CC-C78F21BBF146")]
    
        public class fileSys
    
        {
    
            public string getDirectories()
    
            {
    
                return "Directory A";
    
            }
    
        }
    

    If this does not work for you, please let me know.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by CatFelix Thursday, September 25, 2014 6:06 AM
    Thursday, September 25, 2014 3:00 AM
    Moderator
  • Thanks Fred

    I didn't need the extra statements. I didn't realise that if I ran VS from an account with admin privileges it didn't automatically get all those privileges. Once I ran explicitly via ("Run as Adninistrator" everything worked fine.

    Thanks again

    CatFelix

    Thursday, September 25, 2014 6:12 AM