问题
I have a C# dll and generarted a tlb using regasm. I have given a utility spreadsheet to the users which uses this tlb. The tlb is unregistered and registered (using regasm.exe) everytime a new version of our application is released.
However, at times, when the user is using the spreadsheet after a new release, it throws a 'activex component cannot create instance' error, exactly on the line of code where I create an object of a type. I fix this just by, removing and adding the tlb reference back. (In vba mode-tools-reference-uncheck the tlb-save-and again add). However this is painful since I cannot do this for all users.
I did several tests to replicate the scenario. Like changing the version number of dll and re-registering, adding new methods to interfaces and re-registering. But in all the cases, the spreadsheet works fine without having to remove and re-add the tlb reference.
So, I am confused what could be the scenario where the tlb has to be re-added as reference in the spreadsheets and what could be the probable cause of this. Any help is appreciated.
Thanks, Mani
回答1:
The problem is most likely caused by the fact that UUID of the type library changes and the reference in VBA becomes invalid.
1) There a guy over there who wrote a VBA program to add TLB references and delete invalid ones!
2) This may be related to the fact you uninstall the old version first and then install the new one. RegAsm's manual mentions the reverse order. There's a possibility VBA has some logic to update them automagically that would only work with the update order that M$ guys had in mind.
Another possibility is that Excel was running during the update so it did not update its reference list when it was supposed to.
3) To diagnose the problem further, I'd use procmon.exe. Everything about COM is looked up in the registry so in case of errors, you'll probably bump into the app's inability to find some UUID key.
来源:https://stackoverflow.com/questions/9293440/releasing-new-version-of-tlb-and-when-tlb-needs-to-be-re-referenced