Microsoft KB Archive/241637

= PRB: Adding a New Method to a VB Component in MTS Breaks Existing Client =

Article ID: 241637

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q241637



SYMPTOMS
After adding a new method or property to a class in an ActiveX DLL within a MTS package and recompiling it with binary compatibility, existing clients get one of the following error messages upon deployment of the new client package:

Run-time error '-2147467259 (80004005)':Automation error Unspecified error

-or-

Run-time error '-2147221163 (80040155)':Automation error Interface not registered



CAUSE
This is caused by the fact that when you add a new method to an existing class (interface) and compile the project with binary compatibility, Microsoft Visual Basic (VB) creates a new interface and uses a forwarding mechanism to forward calls made to methods of the old interface to corresponding methods of the new interface.

This works out well between Visual Basic clients and servers when the DLL is registered by calling DllRegisterServer (using REGSVR32.EXE). Unfortunately, the type library knows nothing about the forwarding scheme and that is where MTS Explorer gets information about the component when creating a package.



RESOLUTION
NOTE: The best solution is to avoid the practice of adding methods or properties to classes with existing clients.

To work around this problem, you can do the following:  Create a VBR file for the upgraded component by checking the Remote Server Files checkbox on the Components tab of the Project Properties dialog box before compiling the upgraded DLL. Open the VBR file with Notepad.exe and find the entry that looks like the following:

HKEY_CLASSES_ROOT\INTERFACE\{313BACC6-3D8B-4029-B0D3-B5F4859CEE3E}\Forward = {485D75F2-6AC5-11D3-BB1C-00C04F8ED9F0}

The first UUID {313BACC6-3D8B-4029-B0D3-B5F4859CEE3E} is the interface ID implemented by the older version of your DLL. Make a copy of this UUID. Start Regedit.exe and open the HKEY_CLASSES_ROOT\Interface subkey, then find the UUID you've copied. This UUID subkey should have three additional subkeys of its own:  Forward ProxyStubClsid</li> ProxyStubClsid3</li></ul>

</li> Export the UUID subkey and save it as a REG file.</li> Create the MTS package with the upgraded component as usual. After you install the client package (the exe in the client folder), double-click the REG file on the client machine. This updates the client machine's registry to enable the existing client to access the upgraded component hosted in MTS on the remote server.</li></ol>

<div class="moreinformation_section">

Creating and testing the initial version of a VB DLL:
<ol> Create a Visual Basic ActiveX DLL project and rename it MyDLL.</li>  Add the following code to the default class (Class1): Public Function Function1 As String Function1 = "Function1" End Function </li> Save the project and compile it as MyDll.dll.</li> Create a Visual Basic Standard EXE project and rename it Client.</li> From the Project Menu, select References, check MyDll, and click OK.</li>  Add a CommandButton to the default form (Form1) and paste the following code into Form1's code window: Private Sub Command1_Click Dim oTest As MyDll.Class1 Set oTest = New MyDll.Class1 MsgBox oTest.Function1 End Sub </li> Make sure the project runs and then compile it as Client.exe.</li> Create an MTS package from MyDll.dll and export the package (See the online Help in MTS Explorer for instructions on Exporting Packages.)</li> Deploy the client package and the Client.exe from the Client package created to a client machine, and make sure it runs.</li></ol>

Creating and testing the upgraded VB DLL:
<ol> Reopen the MyDll project.</li> Select Project Properties from the Project menu, check the Remote Server Files checkbox, and select the Binary Compatibility option under the Components tab.</li>  Add the following code to Class1: Public Function Function2 As String Function2 = "Function2" End Function </li> Compile the project. At this point, if you run Client.exe on the development machine, it should work.</li> <li>Delete the MTS package created from the older version of MyDll.dll from MTS Explorer.</li> <li>Create a new package with the new version of MyDll.dll and export it.</li> <li>Uninstall the previous package on the client machine and install the upgraded client package. At this point, when you run Client.exe you get one of the error messages described in the "Symptoms" section. Please see the "Resolution" section of this article for a workaround to this problem.</li></ol>

Additional query words: MTS Binary Compatibility

Keywords: kbinprocsvr kbdll kbprb kbclientserver KB241637

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.