Symptoms
In a Microsoft Visual Basic 2005 or Microsoft Visual Basic .NET application, when you pass late-bound parameters to methods of Microsoft Office objects, you may receive COMException exceptions. For example, when you pass the Name property of a late-bound UserProperty object to the UserProperties.Items method, you may receive the following error message:
An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in microsoft.visualbasic.dll
Additional information: Property is read-only.Note Similar symptoms may also occur when you call methods of other Microsoft Office objects.
Resolution
If you pass a property of an object to a method by reference and the property has a set accessor, Visual Basic calls the set accessor to set the property to the value that the method returns. At compile time, if you pass a property of a late-bound object, the Visual Basic compiler cannot determine whether the property is passed by reference. Also, the Visual Basic compiler cannot determine whether the property has a set accessor. Therefore, the Visual Basic compiler permits the late binder to determine these details at run time.
However, if the relevant objects are Component Object Model (COM) objects at run time, the late binder cannot obtain sufficient information about these details. The late binder uses managed reflection to try to determine these details. The late binder assumes that such method calls involve a ByRef parameter and that the property that you pass has a set accessor. If the property that you pass does not have a set accessor, the Microsoft .NET Framework generates a MissingMethodException exception. The late binder handles the MissingMethodException exception.
The .NET Framework generates a MissingMethodException exception when the call to a method of a Microsoft Office object returns a HRESULT value of COR_E_MISSINGMETHOD. The Microsoft Office object is a COM object. Visual Basic .NET incorrectly assumes that all the methods of Microsoft Office objects return COR_E_MISSINGMETHOD if the property that you pass does not have a set accessor. However, not all the methods of Microsoft Office objects return COR_E_MISSINGMETHOD if the property that you pass does not have a set accessor. Therefore, the behavior that is mentioned in the “Symptoms” section of this article occurs if you pass a property that does not have a set accessor, such as the UserProperty.Name property, to a method.
Note This behavior does not occur if you use early-bound Microsoft Office objects.