2016-11-28 57 views
5

我正在嘗試使用WPF與F#。我已經使用F#空白Windows應用程序模板創建了一個項目(實際上,我使用不同的設置創建了幾個項目)。然後我添加了FSharp.ViewModule和FsXaml.Wpf引用。當項目只有MainWindow.xaml和MainWindow.xaml.fs時,它工作正常。但只要我添加了另一個的.xaml查看文件和.FS視圖模型文件,我得到的「命名空間的ViewModels」聲明下面的錯誤在.FS文件的頂部:FsXaml.Wpf.TypeProvider無法加載

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) 

有一個類似的問題在後面的「FsXaml加載錯誤」(我無法添加評論,因爲我沒有足夠的聲譽)中描述。但我已經嘗試了兩個給出的答案 - 更改CPU和F#運行時 - 並且兩者都不起作用。

我在Windows 7 SP1 64位虛擬機中使用Visual Studio 2015社區版。

  • .NET框架4.5和4.6
  • F#3.0和4.0
  • FSharp.ViewModule 0.9.9和0.9.9.3
  • FsXaml.Wpf:我已經使用下面的框架和DLL版本嘗試2.0.0和2.1.0

編輯1: 在回覆裏德的評論下面,這裏是我的兩個代碼文件顯示錯誤。首先,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 

而這裏的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 

在這兩個文件,我得到的紅色,波浪線下namespace ViewModelsXAML線。該項目將建立在它只有MainWindow.xaml.fs,但不是因爲我加Dialog.fs

編輯2: 這是我.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> 

編輯3:App.fs所賜錯誤「域,構造或成員‘根’是沒有定義。

module main 
open System 
open FsXaml 

type App = XAML<"App.xaml"> 

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

而且packages.config被給予警告‘的‘包’元素未聲明’。

<?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

是否存在\ packages \ FsXaml.Wpf.2.1.0 \ lib \ net45 \ FsXaml.Wpf.TypeProvider.dll?嘗試一些在這個問題的答案http://stackoverflow.com/questions/21753979/visual-studio-could-not-load-file-or-assembly-operation-is-not-supported-erro – Will

+1

你有沒有正確的文件順序? –

+2

如果這不起作用 - 您可能需要顯示代碼和實際的錯誤/位置等。 –

回答

3

在FsXaml的當前版本(2.1和2.0也),你不再有第二個靜態參數:

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

此外,在Dialog.fs,你需要添加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 

我會推薦使用F#4(需要3.1或更高版本)以及最新的FsXaml和FSharp.ViewModule。

+0

謝謝里德,我快到了!但是,在做出這些更改並使用最新版本的FsXaml和FSharp.ViewModule後,我仍然在App.fs中發現「Root」錯誤,它阻止了它的構建,並在packages.config中發出警告 - 請參閱上面的EDIT 3 。 – DenisV

+1

@DenisV刪除.Root ...現在不需要了。這些軟件包是一個虛假的警告。在VS中關閉它會消失。 –

+1

這工作裏德 - 感謝您的幫助! – DenisV