Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:39:27+00:00 2026-06-09T23:39:27+00:00

Upon running the following code, in a project from F# WPF template, to which

  • 0

Upon running the following code, in a project from F# WPF template, to which is added the Nuget Prism

module MainApp

open System
open System.Windows
open System.Windows.Controls
open Microsoft.Practices.Unity
open Microsoft.Practices.Prism.UnityExtensions;
open FSharpx

type Shell = XAML<"MainWindow.xaml">

type App () =
   inherit Application()

   override x.OnStartup e =
      base.OnStartup(e);
      let bt = new BootStrapper()
      bt.Run()

and  BootStrapper () = 
   inherit UnityBootstrapper()

   override x.CreateShell() = 
     let a = x.Container.Resolve<Shell>()

     let b = a.Root
     b :> DependencyObject

   override x.InitializeShell()= 
         base.InitializeShell();
         App.Current.MainWindow <- x.Shell :?> Window
         App.Current.MainWindow.Show()


[<STAThread>]
(new App()).Run() |> ignore

I get no error at compile time, but at runtime an exception says that a.Root is a FrameworkElement, which can not be casted to a Window.

Upon debugging, I see that the runtime content of ‘a’ is of same type than the internal representation of the XAML Type provider, a {FSharpx.TypeProviders.XamlProvider.XamlFile}, as in here, and its internal dictionary is empty.

I am not sure the internal representation of the TP is supposed to surface out.
It looks as if the Type Provider mechanic is ignored by Unity.
I suppose it is because Unity seems to work with reflection to figure out dependencies.

Has anyone experienced a similar behaviour using TP that could shed some light ?

PS :This discrepency compile/runtime in F# is quite suprising. Although there must be a good reason for it I had forgotten the possibility of such occurences !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:39:29+00:00Added an answer on June 9, 2026 at 11:39 pm

    As I see in FSharpX source code, Xaml type provider is erased one – you don’t have Shell type as is in metadata, everything that works with this type is erased to operations with base type – XamlFile. So this

    let a = x.Container.Resolve<Shell>()
    

    will be erased to smth like

    let a = x.Container.Resolve<XamlFile>()
    

    so Unity will just create fresh instance of XamlFile. In contrast, if you try to instantiate Shell directly – then F# compiler will use provided constructors so this

    let a = Shell()
    

    will effectively mean

    let a = XamlFile(XamlReader.Parse( <content-of-xaml-file> ))
    

    In your case you can probably instantiate Shell and then use x.Container.BuildUp() to populate its internals.

    type App () =
       inherit Application()
    
       override x.OnStartup e =
          base.OnStartup(e);
          let bt = new BootStrapper()
          bt.Run()
    
    and  BootStrapper () = 
       inherit UnityBootstrapper()
    
       override x.CreateShell() = 
         let a = Shell()
         x.Container.BuildUp(a.Root) :> _
    
       override x.InitializeShell()= 
             base.InitializeShell();
             App.Current.MainWindow <- x.Shell :?> Window
             App.Current.MainWindow.Show()
    
    
    [<STAThread>]
    (new App()).Run() |> ignore
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across a strange phenomena upon running the following code: #include <iostream> class
I'm getting an Automation error upon running VBA code in Excel 2007. I'm attempting
I am just starting out with the MySQLdb module for python, and upon running
I have the following bit of code which runs a SQL statement: int rowsEffected
Good day! I encountered the following error upon running my JSP program. java.lang.IllegalStateException: PWC3991:
I receive this Run-Time Check Failure upon the return in the following code. I
I use the following code to refresh an autofilter in Excel upon a cell
Upon running rake db:migrate, I'm getting an database configuration does not specify adapter error.
see this fiddle . This upon running gives an error in console. I'm currently
I've got the following code: function failureCallback($host, $port) { print memcache '$host:$port' failed; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.