Error when calling in VB6.0 a C# class library


  I got the attached C# class project so when I add the tbl file as a reference in a VB6 project I am able to instantiate and see all the functions from the class but when the VB6 project is executed I get  -2146233053 Automation Error

 Am I missing something in my class or need to register my C# class library first

Hope you can help me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace AppPerformance
    #region COM+ Settings

    public class Counter

        private static extern bool ApplicationPerformanceCounter(out long lpPerformanceCount);

        private static extern bool ApplicationPerformanceFrequency(out long lpFrequency);

        private long start;
        private long stop;
        private long frequency;
        Decimal multiplier = new Decimal(1.0e9);

        public Counter()
            if (ApplicationPerformanceFrequency(out frequency) == false)
                // Frequency not supported
                throw new Win32Exception();
        }//public ApplicationPerfCounter()

        public void Start()
            ApplicationPerformanceCounter(out start);
        }//public void Start()

        public void Stop()
            ApplicationPerformanceCounter(out stop);
        }//public void Stop()
        public double Duration(int iterations)
            return ((((double)(stop - start) * (double)multiplier) / (double)frequency) / iterations);
        }//public double Duration(int iterations)

    }//public class Counter
}//namespace AppPerformance

Open in new window

Who is Participating?
Todd GerbertConnect With a Mentor IT ConsultantCommented:
That error is because either
1) The .Net COM object must be in the same directory as the VB6 client
2) The .Net object must be installed in the Global Assembly Cache
3) The .Net object must be signed with a strong name, and registered for COM interop using regasm.exe with the /codebase parameter.
Todd GerbertIT ConsultantCommented:
Is your class library registered?
Is this a 64- or 32-bit system?
negreteoAuthor Commented:
It is a 32-bit system and actually I already have checked the checkbox in the Build tab for Register for COM Interop adn then I build the project

I know I am missing something silly but cannot find what
negreteoAuthor Commented:
One more question why can I only add as reference the tlb file and not the dll

Todd GerbertIT ConsultantCommented:
I'm getting the same error, so I'm a little stumped as to why we're seeing that...will do a bit more investigating.
As for why you can reference the TLB, but not the DLL...that's because .Net doesn't generate an actual DLL - that is to say, .Net compiles to an intermediate language called MSIL which is interpreted/compiled at run-time by the .Net engine (much like wscript.exe or cscript.exe interpret a .vbs file at run-time). If you look in the registry at the InProcServer32 key for your COM object, you'll notice it actually refers to mscoree.dll - which is the actual binary run, and in turn loads/interprets the .Net library.
All Courses

From novice to tech pro — start learning today.