What is wrong with:
let (x:UIElement) = upcast new TextBlock()
The error is: The type ‘System.ComponentModel.ISupportInitialize’ is required here and is unavailable. You must add a reference to assembly ‘System, Version=4.0.0….’
TextBlock is a subtype of UIElement…
Note that doing what the error message says does solve the issue, but why is that necessary to do something as basic as upcasting?
As lasseespeholt mentioned in his (now deleted?) answer, there is nothing wrong with your code and you just need to add the reference to
System.dllas the error message suggests.But what is going on?
You are getting the error message on that particular line, because it is the first place where the compiler encounters some type from the
System.dlllibrary (an interfaceISupportInitialize, which is implemented byTextBlock) and realizes that it needs the reference to the library in order to understand the type.Another way to get the same error message is to write this:
In this case, the IntelliSense needs to look at the type (so that it can populate member completion).