title: Casting object to ValueTuple
body: <p>Given the OnNavigatedTo method of the class Page (UWP)</p>
  
  <pre><code>    protected override void OnNavigatedTo(NavigationEventArgs e)
      {
          if (e.Parameter != null)
          {
              var o = (ValueTuple&lt;object, object&gt;) e.Parameter;
              Content = (UIElement) o.Item1;
              this.DataContext = o.Item2;
          }
  
          base.OnNavigatedTo(e);
      }
  </code></pre>
  
  <p>I want to cast the <strong>e.Parameter</strong> (of type object) to a <code>ValueTuple&lt;object, object&gt;</code>. </p>
  
  <p>The parameter carries the instance I want to past as part of a <code>Frame.Navigate</code> call like this:</p>
  
  <p><code>Frame.Navigate(typeof(SomePage), (view, viewModel));</code></p>
  
  <p>The cast should work. It's supposed to be safe because I think that <code>ValueTuple&lt;X, Y&gt;</code> should be able to be casted to <code>ValueTuple&lt;object, object&gt;</code>, right?</p>
  
  <p>However, it throws an <strong>Invalid Cast Exception</strong>.</p>
  
  <p>What's wrong with the casting? </p>
  
  <p>How can I cast from a reference of type <code>object</code> that contains an instance of a tuple, to a typed reference to a tuple?</p>
  
  <h1>Additional info</h1>
  
  <p>The exact exception thrown is this:</p>
  
  <blockquote>
    <p>System.InvalidCastException: 'Unable to cast object of type
    'System.ValueTuple<code>2[System.Object,Reflight.Gui.ViewModels.FlightGalleryViewModel]'
    to type 'System.ValueTuple</code>2[System.Object,System.Object]'.'</p>
  </blockquote>
  
  <p>e.Parameter.GetType() outputs this:</p>
  
  <blockquote>
    <p>{Name = "ValueTuple<code>2" FullName = "System.ValueTuple</code>2[[System.Object,
    System.Private.CoreLib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=7cec85d7bea7798e],[Reflight.Gui.ViewModels.FlightGalleryViewModel,
    Reflight.Gui.ViewModels, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null]]"}
        Assembly: {System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e}
        AssemblyQualifiedName: "System.ValueTuple<code>2[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=7cec85d7bea7798e],[Reflight.Gui.ViewModels.FlightGalleryViewModel,
    Reflight.Gui.ViewModels, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null]], System.Private.CoreLib, Version=4.0.0.0,
    Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
        Attributes: Public | Sealed | Serializable | BeforeFieldInit
        BaseType: {Name = "ValueType" FullName = "System.ValueType"}
        ContainsGenericParameters: false
        CustomAttributes: Count = 2
        DeclaredConstructors: {System.Reflection.ConstructorInfo[1]}
        DeclaredEvents: {System.Reflection.EventInfo[0]}
        DeclaredFields: {System.Reflection.FieldInfo[2]}
        DeclaredMembers: {System.Reflection.MemberInfo[19]}
        DeclaredMethods: {System.Reflection.MethodInfo[14]}
        DeclaredNestedTypes: {System.Reflection.TypeInfo.&lt;get_DeclaredNestedTypes&gt;d__22}
        DeclaredProperties: {System.Reflection.PropertyInfo[2]}
        DeclaringMethod: '((System.RuntimeType)e.Parameter.GetType()).DeclaringMethod' threw an
    exception of type 'System.InvalidOperationException'
        DeclaringType: null
        FullName: "System.ValueTuple</code>2[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=7cec85d7bea7798e],[Reflight.Gui.ViewModels.FlightGalleryViewModel,
    Reflight.Gui.ViewModels, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null]]"
        GUID: {4a04084c-cb2b-378d-aa9c-a77abd9ba77e}
        GenericParameterAttributes: '((System.RuntimeType)e.Parameter.GetType()).GenericParameterAttributes'
    threw an exception of type 'System.InvalidOperationException'
        GenericParameterPosition: '((System.RuntimeType)e.Parameter.GetType()).GenericParameterPosition'
    threw an exception of type 'System.InvalidOperationException'
        GenericTypeArguments: {System.Type[2]}
        GenericTypeParameters: {System.Type[0]}
        HasElementType: false
        ImplementedInterfaces: {System.Type[7]}
        IsAbstract: false
        IsAnsiClass: true
        IsArray: false
        IsAutoClass: false
        IsAutoLayout: true
        IsByRef: false
        IsByRefLike: false
        IsCOMObject: false
        IsClass: false
        IsCollectible: false
        IsConstructedGenericType: true
        IsContextful: false
        IsEnum: false
        IsExplicitLayout: false
        IsGenericMethodParameter: false
        IsGenericParameter: false
        IsGenericType: true
        IsGenericTypeDefinition: false
        IsGenericTypeParameter: false
        IsImport: false
        IsInterface: false
        IsLayoutSequential: false
        IsMarshalByRef: false
        IsNested: false
        IsNestedAssembly: false
        IsNestedFamANDAssem: false
        IsNestedFamORAssem: false
        IsNestedFamily: false
        IsNestedPrivate: false
        IsNestedPublic: false
        IsNotPublic: false
        IsPointer: false
        IsPrimitive: false
        IsPublic: true
        IsSZArray: false
        IsSealed: true
        IsSecurityCritical: true
        IsSecuritySafeCritical: false
        IsSecurityTransparent: false
        IsSerializable: true
        IsSignatureType: false
        IsSpecialName: false
        IsTypeDefinition: false
        IsUnicodeClass: false
        IsValueType: true
        IsVariableBoundArray: false
        IsVisible: true
        MemberType: TypeInfo
        MetadataToken: 33554856
        Module (System.Reflection.MemberInfo): {System.Private.CoreLib.dll}
        Module: {System.Private.CoreLib.dll}
        Name: "ValueTuple<code>2"
        Namespace: "System"
        ReflectedType: null
        StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
        TypeHandle: {System.RuntimeTypeHandle}
        TypeInitializer: null
        UnderlyingSystemType: {Name = "ValueTuple</code>2" FullName = "System.ValueTuple`2[[System.Object, System.Private.CoreLib,
    Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=7cec85d7bea7798e],[Reflight.Gui.ViewModels.FlightGalleryViewModel,
    Reflight.Gui.ViewModels, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null]]"}</p>
  </blockquote>