Reputation: 1020
I need to check if all the references in a project exist to avoid possible errors but I can't find anywhere how to do it in VB.NET. I can do it in VBA like this:
Dim vbProj As VBProject
Dim chkRef As Reference
Set vbProj = ThisWorkbook.VBProject
For Each chkRef In vbProj.References
If chkRef.IsBroken Then
Debug.Print chkRef.Name " reference doesn't exist!"
End If
Next
To be more specific, the project references another program(BarTender) and I need to be able to open files and print them using VB.
I have it installed on my computer but if someone else ran the my project without having Bartender installed it would throw an exception of unknown data type when declaring the object variable.
How do I accomplish this in VB.NET?
Upvotes: 2
Views: 1442
Reputation: 54562
Try enabling Option Strict On
it will prevent late binding which should prevent your code from compiling unless all of the references are present.
From above link:
Restricts implicit data type conversions to only widening conversions, disallows late binding, and disallows implicit typing that results in an Object type.
Also if you click on all files in your solution explorer you will see a References Section if you look in there. Any references with an exclamation point next to them are missing.
Upvotes: 2