2016-11-28 24 views
5

Próbuję użyć WPF z F #. Stworzyłem projekt przy użyciu szablonu F # Empty Windows App (w rzeczywistości utworzyłem kilka z różnymi ustawieniami). Następnie dodałem odwołania do FSharp.ViewModule i FsXaml.Wpf. Działa dobrze, gdy projekt ma tylko MainWindow.xaml i MainWindow.xaml.fs. Ale jak tylko dodaje inny .xaml Zobacz plik i .fs plik ViewModel, otrzymuję następujący błąd na ViewModels „namespace” deklaracją na szczycie plików .fs:FsXaml.Wpf.TypeProvider nie może być załadowany

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) 

istnieje podobny problem opisane w poście "Błąd ładowania FsXaml" (którego nie mogę dodać komentarzy, ponieważ nie mam wystarczającej reputacji). Ale próbowałem obu odpowiedzi podanych tam - zmieniając procesor i środowisko wykonawcze F # - i żaden z nich nie działa.

Używam edycji społeczności Visual Studio 2015 w 64-bitowej maszynie wirtualnej z systemem Windows 7 SP1. I próbowałem stosując następujące ramowe i DLL wersje:

  • NET Framework 4.5 i 4.6
  • F # 3,0 i 4,0
  • FSharp.ViewModule 0.9.9 i 0.9.9.3
  • FsXaml.Wpf 2.0.0 i 2.1.0

EDYTUJ 1: W odpowiedzi na komentarz Reeda poniżej, oto moje dwa pliki kodu, które pokazują błędy. Po pierwsze, 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 

A oto 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 

W obu plikach dostaję czerwony, falowane linie pod namespace ViewModels i pod XAML. Projekt będzie budować, gdy tylko miał MainWindow.xaml.fs, ale nie od dodałem Dialog.fs

EDIT 2: Oto mój plik .fsproj

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <PropertyGroup> 
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform> 
    <ProductVersion>8.0.30703</ProductVersion> 
    <SchemaVersion>2.0</SchemaVersion> 
    <ProjectGuid>b765eaca-f0ed-4898-bfea-fa19fca3788d</ProjectGuid> 
    <OutputType>WinExe</OutputType> 
    <RootNamespace>Test</RootNamespace> 
    <AssemblyName>Test</AssemblyName> 
    <targetframeworkversion>v4.5</targetframeworkversion> 
    <TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion> 
    <Name>Test</Name> 
    </PropertyGroup> 
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 
    <DebugSymbols>true</DebugSymbols> 
    <DebugType>full</DebugType> 
    <Optimize>false</Optimize> 
    <Tailcalls>false</Tailcalls> 
    <OutputPath>bin\Debug\</OutputPath> 
    <DefineConstants>DEBUG;TRACE</DefineConstants> 
    <WarningLevel>3</WarningLevel> 
    <PlatformTarget>x86</PlatformTarget> 
    <DocumentationFile>bin\Debug\Test.XML</DocumentationFile> 
    </PropertyGroup> 
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 
    <DebugType>pdbonly</DebugType> 
    <Optimize>true</Optimize> 
    <Tailcalls>true</Tailcalls> 
    <OutputPath>bin\Release\</OutputPath> 
    <DefineConstants>TRACE</DefineConstants> 
    <WarningLevel>3</WarningLevel> 
    <PlatformTarget>x86</PlatformTarget> 
    <DocumentationFile>bin\Release\Test.XML</DocumentationFile> 
    </PropertyGroup> 
    <PropertyGroup> 
    <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion> 
    </PropertyGroup> 
    <Choose> 
    <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> 
    </When> 
    <Otherwise> 
     <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')"> 
     <FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath> 
     </PropertyGroup> 
    </Otherwise> 
    </Choose> 
    <Import Project="$(FSharpTargetsPath)" /> 
    <ItemGroup> 
    <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" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Reference Include="Accessibility" /> 
    <Reference Include="FSharp.ViewModule.Core.Wpf"> 
     <HintPath>..\..\packages\FSharp.ViewModule.Core.0.9.9.1\lib\net45\FSharp.ViewModule.Core.Wpf.dll</HintPath> 
     <Private>True</Private> 
    </Reference> 
    <Reference Include="FsXaml.Wpf"> 
     <HintPath>..\..\packages\FsXaml.Wpf.0.9.9\lib\net45\FsXaml.Wpf.dll</HintPath> 
     <Private>True</Private> 
    </Reference> 
    <Reference Include="FsXaml.Wpf.TypeProvider"> 
     <HintPath>..\..\packages\FsXaml.Wpf.0.9.9\lib\net45\FsXaml.Wpf.TypeProvider.dll</HintPath> 
     <Private>True</Private> 
    </Reference> 
    <Reference Include="mscorlib" /> 
    <Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 
     <Private>True</Private> 
    </Reference> 
    <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"> 
     <HintPath>..\..\packages\Expression.Blend.Sdk.1.0.2\lib\net45\System.Windows.Interactivity.dll</HintPath> 
     <Private>True</Private> 
    </Reference> 
    <Reference Include="System.Xaml" /> 
    <Reference Include="System.Xml" /> 
    <Reference Include="UIAutomationProvider" /> 
    <Reference Include="UIAutomationTypes" /> 
    <Reference Include="WindowsBase" /> 
    </ItemGroup> 
</Project> 

EDIT 3: App.fs daje błąd „pole, konstruktor, lub członkiem«root»nie jest zdefiniowana.

module main 
open System 
open FsXaml 

type App = XAML<"App.xaml"> 

[<STAThread>] 
[<EntryPoint>] 
let main argv = 
    App().Root.Run() 

i packages.config daje ostrzeżenie«Element «pakiety» nie jest zadeklarowany».

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net45" /> 
    <package id="FSharp.ViewModule.Core" version="0.9.9.3" targetFramework="net45" /> 
    <package id="FsXaml.Wpf" version="2.1.0" targetFramework="net45" /> 
</packages> 
+3

Czy istnieje \ packages \ FsXaml.Wpf.2.1.0 \ lib \ net45 \ FsXaml.Wpf.TypeProvider.dll? Wypróbuj niektóre z odpowiedzi na to pytanie http://stackoverflow.com/questions/21753979/visual-studio-could-not-load-file-or-assembly-operation-is-not-supported-erro – Will

+1

Czy masz prawidłowa kolejność plików? –

+2

Jeśli to nie działa - może być konieczne wyświetlenie kodu i rzeczywistego błędu/lokalizacji/etc. –

Odpowiedz

3

W obecnej wersji FsXaml (2.1, a także 2.0), to już nie to 2nd statyczny parametr:

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

Również w Dialog.fs, trzeba dodać 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 

Polecam za pomocą F # 4 (wymagany jest 3.1 lub późniejszy) oraz najnowszy FsXaml i FSharp.ViewModule.

+0

Dzięki Reed, jestem już prawie na miejscu! Ale po wprowadzeniu tych zmian i korzystaniu z najnowszych wersji FsXaml i FSharp.ViewModule nadal dostaję błąd w "Root" w App.fs, który powstrzymuje go przed budowaniem, oraz ostrzeżenie w packages.config - patrz EDIT 3 powyżej . – DenisV

+1

@DenisV remove .Root ... teraz nie jest potrzebny. pakiety są fałszywym ostrzeżeniem. Zamknij go w VS i odejdzie. –

+1

To działa, Reed - dziękuję za pomoc! – DenisV

Powiązane problemy