• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 16326
  • Last Modified:

Create a .TLB file from a .NET DLL?

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
Tom Knowlton
Asked:
Tom Knowlton
1 Solution
 
AlexFMCommented:
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
 
AlexFMCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Tom KnowltonWeb developerAuthor Commented:
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
 
pml_sivaCommented:
use regsvr32 adodb.dll in the command prompt
0
 
Tom KnowltonWeb developerAuthor Commented:
regsvr32 adodb.dll gave me the following error, I think it was something about could not find DLLRegister entry point or something.

0
 
AlexFMCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
AlexFMCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
I was not getting this error before.
0
 
Tom KnowltonWeb developerAuthor Commented:
Why does the error message refer to CDO.IDataSource

but my actual call is to

CDO.DataSource     (no   "  I   "  before DataSource)

??????
0
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
AlexFMCommented:
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
 
AlexFMCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
Is this making any sense to you????????????

I am lost.....
0
 
Tom KnowltonWeb developerAuthor Commented:
0
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
ptmcompCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
ptmcomp:

I am familiar with this utility...and when i ran it it confirmed 2.7   :)
0
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now