Geeks With Blogs
Dennis Ecclestone's BLOG

We have a project which uses Visual Basic 6 and Crystal Reports 9.  The main application is a standard EXE which contains a Crystal Reports ActiveX Viewer control (CRViewer9) for viewing the reports.  The Crystal Reports are contained in an ActiveX DLL.  What we have found is that sometimes when we make updates to the ActiveX DLL, we will receive a “Type Mismatch” error.  The error message will not occur if we rebuild the main application EXE along with the ActiveX DLL.  As well, the error message will not occur if we run the main application and the DLL from inside of the Visual Basic IDE.

I did some research into this and what I found is that the project for the ActiveX DLL contained a reference to Crystal Report Viewer Control 9 with a path of “C:\Program Files\Microsoft Visual Studio\VB98\crviewer9.oca”.  There is another entry in the list of references for Crystal Report Viewer Control 9 but it has a path of “C:\Program Files\Common Files\Crystal Decisions\2.0\crystalreportviewers\ActiveXViewer\crviewer9.dll”.  There is a second crviewer9.oca file in the “C:\Program Files\Common Files\Crystal Decisions\2.0\crystalreportviewers\ActiveXViewer” directory.  I compared the two crviewer9.oca files and found that they were not the same!!!  I tried to change the reference to the file in the Crystal Decisions folder but nothing seemed to work.  What I was able to find is that the copy of the OCA file in the Visual Studio folder is a cached copy which is created by Visual Basic.  If you delete the crviewer9.oca file in the “C:\Program Files\Microsoft Visual Studio\VB98” directory, Visual Basic will automatically create a new one. 

Where the “Type Mismatch” error is coming from is that each time Visual Basic creates a new OCA file, it also creates new TypeLib registry information for it.  This means that if you recompile the main application EXE and the ActiveX DLL, the application will work fine because both are referencing the same OCA file with the same TypeLib information.  However, if you recompile just the ActiveX DLL at some future point in time, the OCA file and it’s associated TypeLib may have been changed by Visual Basic.  This will result in the “Type Mismatch” error because the main EXE will be referencing the old OCA file and the new version of the ActiveX DLL will be referencing the new OCA file.  The changes in the TypeLib information for the OCA file are the main source of the “Type Mismatch” problem.  You will also encounter this problem if you try to re-build the ActiveX DLL on a different workstation since the two workstations will have different crviewer9.oca files with different TypeLib information.  In order to get around this we tried copying the crviewer9.oca file to each development workstation.  This seemed to work for a while but at some point the crviewer9.oca file must have been re-created by Visual Basic and everything stopped working again. 

By using the Object Browser, I found that the CRViewer9LibCtl library referers to the “C:\Program Files\Microsoft Visual Studio\VB98\crviewer9.oca” file.  However, there is also a CRViewer9Lib library which referers to the “C:\Program Files\Common Files\Crystal Decisions\2.0\crystalreportviewers\ActiveXViewer\crviewer9.dll” file.  By changing all the references in the ActiveX DLL from CRViewer9LibCtl to CRViewer9Lib, I was able to eliminate the “Type Mismatch” error.  However, I still could not remove the project reference to Crystal Report Viewer Control 9 with a path of “C:\Program Files\Microsoft Visual Studio\VB98\crviewer9.oca”.  When I looked at the Controls tab of the Components settings (i.e. menu option Project -> Components), I found that the Crystal Report Viewer Control 9 was checked.  Once I unchecked this, I was able to remove the reference  to Crystal Report Viewer Control 9 with a path of “C:\Program Files\Microsoft Visual Studio\VB98\crviewer9.oca”.  Wow!!! Are OCA files wonderful or what?

Hopefully this will be of some assistance to any poor souls that find themselves in a similar situation.

Posted on Thursday, January 19, 2006 12:05 PM | Back to top


Comments on this post: Type Mismatch Error When Passing ActiveX Control To ActiveX DLL (Visual Basic & Crystal Reports 9)

# re: Type Mismatch Error When Passing ActiveX Control To ActiveX DLL (Visual Basic & Crystal Reports 9)
Requesting Gravatar...
Crystal Reports is Evil and should just die a horrible lingering death. However, in this case, you brought your troubles on yourself.

Two words. Binary Compatibility. Check the project settings for your ActiveX dll that has your reports in it. This needs to be set with a reference to the current version of your dll. In this way, VB will maintain the TypeLib information when you recompile, assuming of course that you have not changed an existing public interface.

Here is a great place to start:
msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconversioncompatibility.asp?frame=true

dave


Left by David Totzke on Jan 20, 2006 3:26 PM

# re: Type Mismatch Error When Passing ActiveX Control To ActiveX DLL (Visual Basic & Crystal Reports 9)
Requesting Gravatar...
Dave, you're quite right about Crystal Reports and the Binary Compatibility issue. In this case though it's not the Binary Compatibilty of the ActiveX DLL which is causing the "Type Mismatch" issue. The main EXE does not explicitly reference the ActiveX DLL with the reports. I have a second ActiveX DLL which contains a set of interfaces for "connecting" the main EXE to the ActiveX DLL with the reports. This ActiveX DLL with the interfaces is referenced by the main EXE and by the ActiveX DLL with the reports and it does have the Binary Compatibility set as you've indicated. I left this out of my original post to keep things simple. Thanks for the feedback.
Left by dennis on Jan 23, 2006 12:31 PM

# re: Type Mismatch Error When Passing ActiveX Control To ActiveX DLL (Visual Basic & Crystal Reports 9)
Requesting Gravatar...
is there an easy way to identify which error handler throws this error?
Left by tea_cup on Feb 15, 2006 7:51 AM

# re: Type Mismatch Error When Passing ActiveX Control To ActiveX DLL (Visual Basic & Crystal Reports 9)
Requesting Gravatar...
Registry Pro is an activeX registry control that gives developers easy and complete access to the power of registry programming. Works with VB, VBA and other ActiveX and COM DLL supporting languages. Includes a detailed help file, comprehensive example programs and a royalty-free re-distributable setup program.

http://www.yaodownload.com/software-development/activex/registrypro/
Left by mark on Apr 20, 2006 11:30 PM

# re: Type Mismatch Error When Passing ActiveX Control To ActiveX DLL (Visual Basic & Crystal Reports 9)
Requesting Gravatar...
I've been beating my head against the wall trying to figure out a similar issue I've been having in c# with the flash activex control. This was it! Two different references for the same types on my machine. I'm glad I stumbled upon this gem of a post.

thanks!
Left by Ian S on Feb 16, 2009 8:20 AM

Your comment:
 (will show your gravatar)


Copyright © Dennis Ecclestone | Powered by: GeeksWithBlogs.net