2

I have an ocx from a third party from which a Primary Interop Assembly (PIA) is created when I add a control to my form. The PIA exposes an ActiveX API to my .NET Assembly.

The strange thing I have found is that when my solution is set to Debug, some functions are missing compared to when my solution is set to Release. The metadata of the PIAs in the Debug and Release folders differ

Release:

#Region "Assembly AxInterop.DATARAYOCXLib, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"
' C:\Users\...\Instruments\obj\x86\Release\AxInterop.DATARAYOCXLib.dll
#End Region

Imports System
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Namespace AxDATARAYOCXLib
    <AxHost.Clsid("{43555bb9-3fe0-11d6-9f4a-00a0cc40a4d2}")> <DefaultEvent("SendMessage")> <DesignTimeVisible(True)>
    Public Class AxGetData
        Inherits AxHost

    Public Overridable Function IsDataReady(index As Short) As Boolean

Debug:

#Region "Assembly AxInterop.DATARAYOCXLib, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"
' C:\Users\...\Instruments\obj\Debug\AxInterop.DATARAYOCXLib.dll
#End Region

Imports System
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Namespace AxDATARAYOCXLib
    <AxHost.Clsid("{43555bb9-3fe0-11d6-9f4a-00a0cc40a4d2}")> <DefaultEvent("SendMessage")> <DesignTimeVisible(True)>
    Public Class AxGetData
        Inherits AxHost

    ' IsDataReady is missing

How can the different configurations target different APIs? I have recently updated the third party software to the latest version (which does not include IsDataReady) and have deleted the dlls in both debug and release folders, and rebuilt. The dlls come back, but Release still sees IsDataReady. What is a good way to solve this?

I have tried this...

  • Set solution to Release
  • Removed references to PIA (AxInterop.DATARAYOCXLib.dll and Interop.DATARAYOCXLib.dll)
  • Opened a form and added controls to the Toolbox found in the ocx in Program Files. This action creates the PIA (AFAIK) and adds references.
  • Deleted bin and obj folders
  • Build
  • Check the API. IsDataReady is there

Then I repeated all the steps after setting solution to Debug instead. IsDataReady is not there.

I contacted the vendor and they said this function is deprecated and is not included in the latest ocx. However I definitely see it when building in Release.

djv
  • 15,168
  • 7
  • 48
  • 72
  • Check the timestamp of the exe files (debug, release) in the project bin folder and any dll in these folders. The timestamp of the files in debug and release should be the same. – jdweng Jul 22 '19 at 20:33
  • @jdweng my class library uses the ocx, and the PIA is created and referenced automatically, and the PIA timestamp in each debug and release directory of the class library corresponds to when the project is (re)built. (At this point no exe is involved because the exe project doesn't reference this class library, it just copies the class library bin folder contents to its own bin folder in a post-build event.) – djv Jul 22 '19 at 20:55
  • I'm not sure I fully understand what you are experiencing, but is it possible that your Debug and Release configurations are targeting different platforms? – TnTinMn Jul 22 '19 at 21:16
  • @TnTinMn they both target x86. I have a lot of 32 bit libraries which make this a necessity – djv Jul 22 '19 at 21:21
  • When you update your source you must rebuild both the debug and release executables for both to work. If you only update one, then the other will not work. – jdweng Jul 22 '19 at 23:38
  • @jdweng yes, I did rebuild both. First I cleaned both and rebuilt. The PIA was generated and had a contemporary timestamp. Also, it is a class library, not executable. – djv Jul 23 '19 at 02:18
  • There is no reason that your release version couldn't use the API debug version. When I add API to a project in I add Existing Item and then always browse for the API Debug folder. When I make a release version it still targets the API debug folder. – jdweng Jul 23 '19 at 08:56
  • @jdweng I just have an ocx from the vendor. Since I see the deprecated member I probably have some sort of reference to the old version, somewhere. But cleaning or manually deleting the PIA doesn't clear it out. I don't have an API debug folder – djv Jul 23 '19 at 17:36
  • All the referenced project should has an executable (or dll) in the main project bin folder to verify everything was up[dated you can check the date of these executables. Since you done a clean all the dlls should have new dates. – jdweng Jul 24 '19 at 08:39
  • @jdweng yes they do have new dates. I checked the registry and there was only one registered ocx, which was the correct one. I still haven't solved it. I wasn't able to replicate it in a new project so it may just be some configuration issue in my project. – djv Jul 24 '19 at 14:41

1 Answers1

1

I used Windows Search to delete every bin and obj directory in my entire solution directory, and rebuilt. Some manual building for some lower level dependent projects was necessary. This solved the problem. Now my Debug and Release builds both show the correct API.

I had tried deleting those directories for just the offending project and its immediate dependencies, but this was not enough by itself.

I am still not sure why this was necessary, or why the project would not overwrite the interop assembly from the latest ocx, even when it was the only version registered on the PC. I hope I don't need to do this every time I get a new version of the ocx, but I'll keep it in mind.

djv
  • 15,168
  • 7
  • 48
  • 72