Windows Phone Developers

Sunday, April 27, 2008

Late bound resolution in .NET

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


Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment