Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# Com assembly not working unless doing debug --> compile or...

Status
Not open for further replies.

christhedonstar

Programmer
Apr 9, 2007
215
GB
tools --> references --> ok.

We have some software that registers an assembly and creates a tlb file.

Recently we've noticed a problem with this scenario

1) Excel workbook myWorkBook.xls has reference to myfile.tlb
2) myfile.dll is unregistered and myfile.tlb deleted
3) Excel workbook myWorkBook.xls is opened
4) myfile.dll is registered and myfile.tlb created
5) Try to run some functionality that uses myfile.tlb

we get can't find project or library and then in the reference click ok and then it works.

Ok think I've worked it out - think I need to compile the workbook and then save.

Will let you know if thats not the case.
 
Ok that wasn't the issue :( - somehow it was working for a bit but now I've deleted that file because I thought it was to do with compilation. So there is something you can do to fix it.
Any ideas?
 
One workaround is to remove and then add the reference again. One thing I've found is that if you have this code

on error goto ErrHandler

VbProject.references.addfromfile "C:\doesntexist.tlb"

ErrHandler:
debug.print "An error occured and we caught it"

Instead of getting the debug.print message you get a run-time error '48' Error in loading dll.

Why is the error not caught?

Thanks,

Chris
 
What are error trapping settings (VBE: Tools>Options>General tab)?

combo
 
Its set on Break on Unhandled Errors.

There is something about this call, maybe being low level or something?
 
Try reference excel workbook first, if your code runs in the same excel file:
ThisWorkbook.VBProject.references.addfromfile "C:\doesntexist.tlb"


combo
 
Ok I'll give that a go. Strange that the runtime error doesn't get caught isn't it...
 
Didn't help on error resume next lets me skip over it but I cannot use normal error handling. Did you get it working ?
 
You could try to split the code into two workbooks - the first a helper file that test library file, if exist, open the myWorkBook.xls (with reference added or with code adding the reference).
Maybe late binding could be helpful too.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top