FsXaml.Wpf.TypeProvider cannot be loaded


I'm trying to use WPF with F#. I've created a project using the F# Empty Windows App template (in fact, I've created several using different settings). Then I added the FSharp.ViewModule and FsXaml.Wpf references. It works fine when the project only had MainWindow.xaml and MainWindow.xaml.fs. But as soon as I added another .xaml View file and a .fs ViewModel file, I get the following error on the "namespace ViewModels" declaration at the top of the .fs files:

The type provider '...\packages\FsXaml.Wpf.2.1.0\lib\net45\FsXaml.Wpf.TypeProvider.dll' reported an error: Assembly attribute 'TypeProviderAssemblyAttribute' refers to a designer assembly 'FsXaml.Wpf.TypeProvider' which cannot be loaded or doesn't exist. Could not load file or assembly 'file:///...\packages\FsXaml.Wpf.2.1.0\lib\net45\FsXaml.Wpf.TypeProvider.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

There's a similar problem described in the post "FsXaml load error" (which I can't add comments to because I don't have enough reputation). But I've tried both the answers given there - changing the CPU and the F# runtime - and neither one works.

I'm using Visual Studio 2015 Community edition in a Windows 7 SP1 64-bit virtual machine. And I've tried using the following framework and DLL versions:

  • NET Framework 4.5 and 4.6
  • F# 3.0 and 4.0
  • FSharp.ViewModule 0.9.9 and
  • FsXaml.Wpf 2.0.0 and 2.1.0

EDIT 1: In reply to Reed's comment below, here are my two code files that are showing the errors. First, MainWindow.xaml.fs:

namespace ViewModels
open FSharp.ViewModule
open FsXaml

type MainView = XAML<"MainWindow.xaml", true>

type MainViewModel() as self = 
    inherit ViewModelBase()    

    let text = self.Factory.Backing (<@ self.Text @>, "")

    let newCommand = self.Factory.CommandSync (fun _ -> self.Text <- "File > Open")
    let openCommand = self.Factory.CommandSync(fun _ -> self.Text <- "File > Open")
    let closeCommand = self.Factory.CommandSync(fun _ -> self.Text <- "File > Close")
    let exitCommand = self.Factory.CommandSync(fun _ -> self.Text <- "File > Exit")

    member x.Text with get() = text.Value and set value = text.Value <- value

    member x.NewCommand = newCommand
    member x.OpenCommand = openCommand
    member x.CloseCommand = closeCommand
    member x.ExitCommand = exitCommand

And here's Dialog.fs:

namespace ViewModels
open FSharp.ViewModule

type DialogView = XAML<"Dialog.xaml", true>

type DialogVM() as self =
    inherit ViewModelBase()    

    let name = self.Factory.Backing (<@ self.Name @>, "")
    let address = self.Factory.Backing (<@ self.Address @>, "")

    member x.Name with get() = name.Value and set value = name.Value <- value
    member x.Address with get() = address.Value and set value = address.Value <- value

In both files I get red, squiggly lines under namespace ViewModels and under XAML. The project would build when it only had MainWindow.xaml.fs, but not since I added Dialog.fs

EDIT 2: Here's my .fsproj file

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
    <When Condition="'$(VisualStudioVersion)' == '11.0'">
      <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
        <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
      <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
  <Import Project="$(FSharpTargetsPath)" />
    <None Include="Dialog.xaml" />
    <Compile Include="Dialog.fs" />
    <Resource Include="MainWindow.xaml" />
    <Compile Include="MainWindow.xaml.fs" />
    <Resource Include="App.xaml" />
    <Compile Include="App.fs" />
    <Content Include="App.config" />
    <Content Include="packages.config" />
    <Reference Include="Accessibility" />
    <Reference Include="FSharp.ViewModule.Core.Wpf">
    <Reference Include="FsXaml.Wpf">
    <Reference Include="FsXaml.Wpf.TypeProvider">
    <Reference Include="mscorlib" />
    <Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="PresentationUI" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Numerics" />
    <Reference Include="System.Windows.Interactivity">
    <Reference Include="System.Xaml" />
    <Reference Include="System.Xml" />
    <Reference Include="UIAutomationProvider" />
    <Reference Include="UIAutomationTypes" />
    <Reference Include="WindowsBase" />

EDIT 3: App.fs is giving the error "The field, constructor, or member 'Root' is not defined.

module main
open System
open FsXaml

type App = XAML<"App.xaml">

let main argv =

And packages.config is giving the warning "The 'packages' element is not declared".

<?xml version="1.0" encoding="utf-8"?>
  <package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net45" />
  <package id="FSharp.ViewModule.Core" version="" targetFramework="net45" />
  <package id="FsXaml.Wpf" version="2.1.0" targetFramework="net45" />
asked on Stack Overflow Nov 28, 2016 by DenisV • edited Dec 1, 2016 by DenisV

1 Answer


In the current version of FsXaml (2.1, and also 2.0), you no longer include the 2nd static parameter:

 type MainView = XAML<"MainWindow.xaml"> // Remove the 2nd arg here ... 

Also, in Dialog.fs, you need to add open FsXaml:

namespace ViewModels
open FSharp.ViewModule
open FsXaml // This is probably causing the specific error you're seeing

type DialogView = XAML<"Dialog.xaml"> // Again, remove the true

I would recommend using F# 4 (3.1 or later is required), and the latest FsXaml and FSharp.ViewModule.

answered on Stack Overflow Nov 30, 2016 by Reed Copsey

User contributions licensed under CC BY-SA 3.0