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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Todd GerbertIT 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.