Solved

Create a .TLB file from a .NET DLL?

Posted on 2004-04-30
25
14,840 Views
Last Modified: 2007-12-19
I am using adodb.dll in a C# class.

why am I not able to do this:

regasm adodb.dll /tlb


I get the following error:

[[command line output]]


C:\EES\BIN\RELEASE>regasm adodb.dll /tlb
Microsoft (R) .NET Framework Assembly Registration Utility 1.0.3705.288
Copyright (C) Microsoft Corporation 1998-2001.  All rights reserved.

Types registered successfully
RegAsm error: CLR assembly c:\ees\bin\release\adodb.dll was imported from a type
 library and can not be re-exported to a type library.  Make sure the type libra
ry from which the assembly was imported is registered.


What does this message mean.......and is there still a way to create a TLB file from the DLL?
0
Comment
Question by:knowlton
25 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10965476
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10966283
regasm utility is used to registrate .NET Dll as COM Dll, which makes it available for unmanaged client. Your task is opposite - to use unmanaged COM dll in C# code. To do this, add this Dll to the Project References.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10966354
Actually, adodb.dll is managed library, but also in this case you need to add it's reference to your project. adodb.dll is managed wrapper for unmanaged ADO library. You don't need regasm tool in this case, you can use this library directly in C# project.

Consider the case when you are working with unmanaged (for example, VB6) project, and want to use .NET Dll. This is a place to use regasm. But unmanaged project doesn't need to use adodb.dll, it can use directly original ADO Dll, so regasm is not needed also in this case.

In the Project Explorer right-click on References, select Add Reference. In .NET tab select adodb. Now all ADO objects are available using  ADODB prefix, or add line:
using ADODB;
and use them directly.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10968636
For some reason I am getting an error when trying to use the ADODB dll.

"Interface Not Regsitered"

This is a COM problem is it not?

If I am referencing the ADODB.dll in my project References....then why isn't COM picking it up?
0
 
LVL 4

Expert Comment

by:pml_siva
ID: 10975870
use regsvr32 adodb.dll in the command prompt
0
 
LVL 5

Author Comment

by:knowlton
ID: 10979356
regsvr32 adodb.dll gave me the following error, I think it was something about could not find DLLRegister entry point or something.

0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10983619
Read this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconfillingdatasetwithadorecordset.asp

This article describes how to generate ADODB.DLL using command:
TlbImp "C:\Program Files\Common Files\System\Ado\msado15.dll" /out:ADODB.dll

Try to do this, what result do you have? Do you have msado15.dll on your computer? Try to register it using regsvr32 abd generate adodb.dll after this.


Having ADODB.Dll, try this:

http://support.microsoft.com/default.aspx?scid=kb;en-us;810098

0
 
LVL 5

Author Comment

by:knowlton
ID: 10987947
Alex:  

I have msado15.dll on my computer at location:

C:\Program Files\Common Files\System\ado

I noticed that inside this folder there are other files.  Not sure about their relevance but here is a list:

07/26/2000  11:00a                 667 adoapt15.reg
07/26/2000  11:00a                 640 adofre15.reg
05/04/2001  01:05p              14,236 adojavas.inc
05/04/2001  01:05p              14,562 adovbs.inc
07/26/2000  11:00a                  26 makapt15.bat
07/26/2000  11:00a                  26 makfre15.bat
06/27/2001  02:22p                 543 MDACReadme.htm
07/13/2001  10:30a              24,576 msader15.dll
07/13/2001  10:30a             487,424 msado15.dll
07/13/2001  09:39a              61,440 msado20.tlb
07/13/2001  09:39a              61,440 msado21.tlb
07/13/2001  09:39a              81,920 msado25.tlb
07/13/2001  09:39a              81,920 msado26.tlb
07/13/2001  10:30a             159,744 msadomd.dll
07/13/2001  10:30a              49,152 msador15.dll
07/13/2001  10:30a             180,224 msadox.dll
07/13/2001  10:30a              53,248 msadrh15.dll
07/13/2001  10:31a              90,112 msjro.dll


==========================================

When I ran

TlbImp "C:\Program Files\Common Files\System\Ado\msado15.dll" /out:ADODB.dll

Here was the result:

TlbImp warning: Primary interop assembly 'ADODB, Version=7.0.3300.0, Culture=neu
tral, PublicKeyToken=b03f5f7f11d50a3a' is already registered for type library 'C
:\Program Files\Common Files\System\ado\msado15.dll'.
Type library imported to C:\Program Files\Common Files\System\ado\adodb.dll



What should I do?  :)

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10988170
Now try to use this adodb.dll selecting it as reference using Browse button. Try to add it to GAC as described in the second link of my previous post and after this add reference from the list (adodb.dll is in the beginning).
If all this doesn't succeed, try to add COM reference directly to msado15.dll, this should have the same result, but proxy Dll is generated in the project directory.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988325
Since I added the adodb.dll back into my project source I am now getting this compile error:

N:\ClientDevelopment\NEO\BuyersFund\ExchangeEventSinkClassLibrary\ExchEventSink.cs(137): The best overloaded method match for 'CDO.IDataSource.Open(string, object, ADODB.ConnectModeEnum, ADODB.RecordCreateOptionsEnum, ADODB.RecordOpenOptionsEnum, string, string)' has some invalid arguments
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988332
I was not getting this error before.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988354
Why does the error message refer to CDO.IDataSource

but my actual call is to

CDO.DataSource     (no   "  I   "  before DataSource)

??????
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by:knowlton
ID: 10988414
C:\Program Files\Microsoft.NET\Primary Interop Assemblies>gacutil /i adodb.dll

Microsoft (R) .NET Global Assembly Cache Utility.  Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.

Assembly successfully added to the cache

C:\Program Files\Microsoft.NET\Primary Interop Assemblies>



So adding to GAC worked?
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988518
Alex:

I tried adding the file

msado15.dll

from this location:

C:\Program Files\Common Files\System\ado


======================================

The result was the following showed up in my References:


ADODB
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10988563
ExchEventSink.cs - is this your file or proxy generated by Visual Studio?
Maybe adodb.dll supplied with Visual Studio was generated from another version of msado15.dll.
Try to start new project and add adodb.dll reference to it - what happens now?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10988586
Adding of msado15.dll directly works, this is good. The difference is that proxy Dll is generated with your project, and adodb.dll is the same proxy supplied by Microsoft. However, this is transparent for your code, so you already have something.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988645
Alex:

Okay.......taking a deep breath......inhale....exhale..........

1)  I created a brand new C# Windows Application.

2)  The very next thing I did was go to References....Add References.

3)  Under the .NET tab, about 2 items down was adodb.  Version shown was 7.0.3300.0.  Path was:  C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll

4)  Once I selected this file what shows up in my References is lowercase adodb.

===========================================================


So when I add msado15.dll (by browsing to location C:\Program Files\Common Files\System\ado) in References I get

ADODB  (uppercase)

But when I add adodb (by going to Add References, .NET tab, adodb) I get

adodb  (lowercase)
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988648
Is this making any sense to you????????????

I am lost.....
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988686
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988734
Alex:

>>>> ExchEventSink.cs - is this your file or proxy generated by Visual Studio?


ExchEventSink.cs   contains the source code for my Exchange Server 2000 event sink.

When a new e-mail arrives and is saved to a particular folder....the code inside ExchEventSink.cs is executed.  THIS PART WORKS......BUT......the ADODB code fails and generates this message:

Interface not registered   at ADODB.RecordsetClass.MoveFirst()
   at MyEventSink.ExchEventSink.Process_mail(String bstrURLItem)
0
 
LVL 5

Author Comment

by:knowlton
ID: 10988788
Alex:


Apparently I now have 3 copies of the file adodb.dll on my hard drive:

See the last post:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20976258.html
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 10990993
Do you have MDAC 2.7 or higher? Here you can find a program to verify your MDAC installation:
http://www.microsoft.com/downloads/details.aspx?FamilyID=8f0a8df6-4a21-4b43-bf53-14332ef092c9&displaylang=en
0
 
LVL 5

Author Comment

by:knowlton
ID: 10991285
ptmcomp:

I am familiar with this utility...and when i ran it it confirmed 2.7   :)
0
 
LVL 5

Author Comment

by:knowlton
ID: 11119903
UPDATE:

Well, guess what?

I finally had a major breakthrough on this @!#$^% problem that has been driving me crazy for the last few weeks!!!!!!!


It is a very small change.

Apparently the method   MoveFirst(   ) does not work so well with Exchange.

This was the cause of my COMException:   "Interface not registered" error message this entire time.


The solution is to use    Move(1,0)     instead of MoveFirst(  ).


That's it.   Simple.

This answer came courtesy of Tom Rizzo, an author who was kind enough to correspond with me and help me figure-out finally what the problem was.:

Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint?  Check out http://www.microsoft.com/MSPress/books/5517.asp

My I aslo reommend:

.NET and COM: The Complete Interoperability Guide  ISBN:067232170X
http://www.amazon.ca/exec/obidos/ASIN/067232170X/componentsnot-20/701-9386310-4703553
0
 
LVL 5

Author Comment

by:knowlton
ID: 11120246
More on the MoveFirst problem I described:

http://support.microsoft.com/default.aspx?scid=kb;en-us;273791


If you are getting into Event Sinks....I recommend the following tutorial:

http://www.codeproject.com/csharp/CsManagedEventSinksHooks.asp

Make sure and read the article questions and follow-ups at the bottom!

There are a few caveats.  E-mail me at my Profile e-mail address and we can talk about them.  :)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now