来自 assembly 的类型是使用旧版本的 blend sdk 构建的,在 windows presentation foundation 4 项目中不受支持

the type from assembly is built with an older version of blend sdk and is not supported in a windows presentation foundation 4 project

我在 VS 2013 中创建了一个 WPF 项目。升级到 VS 2015 后,在从 Blend SDK 派生的类型的设计器中显示此错误:

the type from assembly is built with an older version of blend sdk and is not supported in a windows presentation foundation 4 project

您可以通过手动更改 .sln 和 .csproj 文件中的版本号来解决此问题。

在 .csproj 和 .csproj.user 将 ToolsVersion 更改为您当前的 Visual Studio 版本。 VS 2013 是版本 12,VS 2015 是版本 14。

在 .sln 中将 VisualStudioVersion 更改为当前版本,您可以在关于 window.

中找到它

同时将 Microsoft Visual Studio Solution File, Format Version 更改为您当前的版本(例如 14.00、12.00)

注意:这仅适用于内置程序集。如果外部依赖项(如 Prism)导致此错误,您必须使用新的 Blend SDK 重新编译它们。您也可以尝试更新依赖项,也许最新版本已经使用最新的 Blend SDK 编译。

  1. 运行 作为管理员的命令提示符

  2. 将目录更改为 Blend SDK:cd C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.5\Libraries\

  3. 注册 DLL:gacutil -i System.Windows.Interactivity.dll

  4. 重启Visual Studio

参考:https://connect.microsoft.com/VisualStudio/feedback/details/755407/xaml-designer-will-not-display-when-using-blend-sdk-behaviors

只有 Microsoft Visual Studio 解决方案文件,格式版本更改为 14.00 对我有用。

None 这里的其他答案对我有用。最终解决的是删除SDK文件夹中.NET v4.0版本的文件:

C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries\

我正在通过 NuGet 引用 v4.5 文件,但 designer 似乎在上述文件夹中找到该文件。 v4.0 文件未在 GAC 中注册。

在使用 Visual Studio 2017 时遇到了类似的问题,但上面的 none 答案完全为我解决了。找到了一个 Microsoft 开发人员社区 page,其中有一个解决方法可以解决问题。 Bran Hagger 的评论建议从解决方案目录中删除 .vs 文件夹。这个额外的步骤清除了缓存并导致 Visual Studio 重建它。

这也可能是因为您混合使用了不同版本的 System.Windows.Interactivity.dll,尤其是当您从 nuget 获取 SDK 时,有几个不同的包提供它,例如:

https://www.nuget.org/packages/Expression.Blend.Sdk/ https://www.nuget.org/packages/System.Windows.Interactivity.WPF/

在这种情况下,您必须在项目之间同步这些库。

流行的答案是有效的,但由于开发人员世界的情况总是在变化,我想我会注意到现在有一​​个 (IMO) 更好的解决方案。

2018 年 12 月,Microsoft 为 WPF 的 XAML 行为发布了官方、开源、受支持的 NuGet 包。 (UWP 有一个单独的包。)迁移到这个包非常容易。您需要卸载当前的 NuGet 包,删除几个引用,安装此包,并更改 using 语句(或 FQN)。

https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Wpf/

https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/

我在这个 SO 答案中读到了它,所以归功于那个 OP:

How to add System.Windows.Interactivity to project?

删除解决方案文件夹中的 .vs 文件解决了问题。在我更新我的 Visual Studio 2017 并打开之前使用 Visual studio 2017 的旧版本构建的项目后,我遇到了这个问题。