Late bound resolution; runtime errors could occur
This error (Error ID: BC42017) occurs because an object is assigned to a variable declared to be of the Object Data Type.
When you declare a variable as Object, the compiler must perform late binding, which causes extra operations at run time. It also exposes your application to potential run-time errors. For example, if you assign a Form to the Object variable and then try to access the XmlDocument..::.NameTable property, the runtime throws a MemberAccessException because the Form class does not expose a NameTable property.
If you declare the variable to be of a specific type, the compiler can perform early binding at compile time. This results in improved performance, controlled access to the members of the specific type, and better readability of your code.
To avoid this error it is better to declare the data type of the variable
Private app As Excel.Application
Instead of
Private app As Object
No comments:
Post a Comment