C# Class Library - MS Office - VBA Macro - Registration

Answered C# Class Library - MS Office - VBA Macro - Registration

  • 1 mai 2012 12:08
     
     

    I’ve build a C# class library that I plan to access via a Microsoft Office VBA macro. The class definition is pretty simple:

    .

    .

    using Atlassian.Jira;

    using Atlassian.Jira.Remote;

     

    // This class library is used by the ProblemReport email server robot to submit PERU reports into the JIRA database.

    // NOTE: if for any reason fields are added or removed for the JIRA issue database this code most likely will

    //          need to be updated, especially for "required" fields.

     

    namespace PeruToJira

    {

         /// <summary>

        /// Submit a PERU report including attached files to the JIRA Issue Database

        /// </summary>

        public class SubmitReport

        {

            /// <summary>

            /// Submit PERU report data to the JIRA Database

            /// </summary>

            public int Submit(string strXMLFilePath, string strGivenTitle, string strGivenDescription, out string strReportKey)

            {

    .

    }

    After copying the dll and it’s other reference files (Atlassian) to the system I plan on invoking this on I register the class library using regasm like this:

    "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe" /verbose "c:\Program Files\jira\PeruToJira.dll"

    And the results of the registration are:

    [HKEY_CLASSES_ROOT\PeruToJira.SubmitReport]

    @="PeruToJira.SubmitReport"

    [HKEY_CLASSES_ROOT\PeruToJira.SubmitReport\CLSID]

    @="{9EBB9A22-448A-3719-AB97-8B13B4A96B1B}"

    [HKEY_CLASSES_ROOT\CLSID\{9EBB9A22-448A-3719-AB97-8B13B4A96B1B}]

    @="PeruToJira.SubmitReport"

    [HKEY_CLASSES_ROOT\CLSID\{9EBB9A22-448A-3719-AB97-8B13B4A96B1B}\InprocServer32]

    @="mscoree.dll"

    "ThreadingModel"="Both"

    "Class"="PeruToJira.SubmitReport"

    "Assembly"="PeruToJira, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

    "RuntimeVersion"="v2.0.50727"

    [HKEY_CLASSES_ROOT\CLSID\{9EBB9A22-448A-3719-AB97-8B13B4A96B1B}\InprocServer32\1.0.0.0]

    "Class"="PeruToJira.SubmitReport"

    "Assembly"="PeruToJira, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

    "RuntimeVersion"="v2.0.50727"

    [HKEY_CLASSES_ROOT\CLSID\{9EBB9A22-448A-3719-AB97-8B13B4A96B1B}\ProgId]

    @="PeruToJira.SubmitReport"

    [HKEY_CLASSES_ROOT\CLSID\{9EBB9A22-448A-3719-AB97-8B13B4A96B1B}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

    In using the macro I have referenced the PeruToJira via the VBA editor. The vba code looks like this:

    Sub ProcessSelectedEmail()

        Dim objApp As Application

        Dim selEmails As Selection

        Dim objEmail As MailItem

       

        Dim objp2Jira As PeruToJira.SubmitReport

        Set objp2Jira = New PeruToJira.SubmitReport

              

        Dim rtnErrorCode As Long

        Dim strReportKey As String

    rtnErrorCode = objp2Jira.Submit("c:\xx.xml", "strTitle", "strDescription", strReportKey)

    Now when I execute the BOLD lines I get an exception: 80070002 – Automation error – The system cannot find the file specified.

    So I assume it cannot find the PerToJira.dll. What I do not see in the registry is a “full path” to where the dll lives and I think that is the problem.

    Can anyone provide any help.

    Of course if I do all this testing on my build system everything works fine. When I build the class library on the build system it registers itself as part of the build and the entries are a lot different than what I’ve shown above.

    I've also run a depends and everything seems to be inplace as far as the PeruToJira.dll. Is there another way to test this w/o getting MS Office involved?

    TIA

Toate mesajele

  • 2 mai 2012 07:47
    Moderator
     
     Răspuns Are cod
        [System.Runtime.InteropServices.ComVisible(true)]
        public class Class1
        {
            public string MethodA() 
            {
                return "abcd";
            }
        }
    Sub methodb()
    Dim a As New Class1
    MsgBox a.methoda
    End Sub
    regasm /codebase ClassLibrary1.dll /tlb:ClassLibrary1.tlb /verbose

    If the assembly is not in the GAC, then you will need to use the /codebase switch, if not you will get that error message.

    or you can use this function in Visual Studio at debug time to reg the assembly when build:
    Project property -> Build -> Register for COM interop 

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us