Xamarin.Forms - XamlCompilation缺少方法异常

7

我希望提高我的Xamarin.Forms UWP应用程序的性能,因为在发布模式下("检查.NET本地化"),它非常缓慢。因此,我在PCL项目中应用XAMLC来优化程序集级别的性能:

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace MyApp
{
}

但是使用这个属性时,我收到了运行时错误:

“未找到方法:‘Void Xamarin.Forms.Xaml.Internals.SimpleValueTargetProvider..ctor(System.Object[])’”。

根据此:

https://github.com/xamarin/Xamarin.Forms/blob/master/docs/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.Internals/SimpleValueTargetProvider.xml

SimpleValueTargetProvider类有两个版本:

  • 1.5.0.0 - 只有一个参数System.Object[]的构造函数
  • 2.0.0.0 - 有两个参数System.Object[]和System.Object的构造函数

我使用Xamarin.Forms 2.3.3.163-pre3,所以在我的项目中我使用了第二个版本(当我导航到Xamarin.Forms.Xaml.Internals中的SimpleValueTargetProvider时,我可以看到带有2个参数的构造函数)。我理解的是,显然“某些东西”仍在调用SimpleValueTargetProvider 1.5.0.0,但我不知道这是什么东西。

我删除了所有第三方组件,但没有帮助。我使用融合日志找出问题所在,但这就是我得到的全部内容(老实说,我不知道这是否与我正在面临的问题有关):

> *** Assembly Binder Log Entry  (10/26/2016 @ 9:09:42 PM) ***
> 
> The operation failed. Bind result: hr = 0x80070002. The system cannot
> find the file specified.
> 
> Assembly manager loaded from: 
> C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under
> executable  C:\Program Files (x86)\Microsoft Visual
> Studio\VS15Preview\Common7\IDE\devenv.exe
> --- A detailed error log follows. 
> 
> === Pre-bind state information === LOG: DisplayName = XamlDesignerFaultInjection  (Partial) WRN: Partial binding information
> was supplied for an assembly: WRN: Assembly Name:
> XamlDesignerFaultInjection | Domain ID: 1 WRN: A partial bind occurs
> when only part of the assembly display name is provided. WRN: This
> might result in the binder loading an incorrect assembly. WRN: It is
> recommended to provide a fully specified textual identity for the
> assembly, WRN: that consists of the simple name, version, culture, and
> public key token. WRN: See whitepaper
> http://go.microsoft.com/fwlink/?LinkId=109270 for more information and
> common solutions to this issue. LOG: Appbase = file:///C:/Program
> Files (x86)/Microsoft Visual Studio/VS15Preview/Common7/IDE/ LOG:
> Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base =
> NULL LOG: AppName = devenv.exe Calling assembly : (Unknown).
> === LOG: This bind starts in default load context. LOG: Using application configuration file:
> C:\Users\blaze\AppData\Local\Microsoft\VisualStudio\15.0_2f751565\devenv.exe.config
> LOG: Using host configuration file:  LOG: Using machine configuration
> file from
> C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
> LOG: Policy not being applied to reference at this time (private,
> custom, partial, or location-based assembly bind). LOG: Attempting
> download of new URL file:///C:/Program Files (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/XamlDesignerFaultInjection.DLL. LOG:
> Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PublicAssemblies/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PublicAssemblies/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/Debugger/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/Debugger/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/x86/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/x86/XamlDesignerFaultInjection/XamlDesignerFaultInjection.DLL.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/XamlDesignerFaultInjection.EXE. LOG:
> Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PublicAssemblies/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PublicAssemblies/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/Debugger/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/Debugger/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/x86/XamlDesignerFaultInjection.EXE.
> LOG: Attempting download of new URL file:///C:/Program Files
> (x86)/Microsoft Visual
> Studio/VS15Preview/Common7/IDE/PrivateAssemblies/DataCollectors/x86/XamlDesignerFaultInjection/XamlDesignerFaultInjection.EXE.
> LOG: All probing URLs attempted and failed.

这是 Xamarin.Forms 或 XamlCTask 中的一个 bug 吗?有人遇到过这个问题或知道如何解决吗?
  • Windows 10 64 位
  • Visual Studio 15 预览版 5
  • Xamarin 4.2.1.14
  • Xamarin.Forms 2.3.3.163-pre3
提前感谢。
3个回答

12

这很可能是IDE或项目级别的缓存问题。

如果是在IDE级别: - 进行清理 - 重启 VS 或 XS - 重新构建

但你可能已经尝试过了。

我猜测其中一个nuget更新没有正确清除,并且您的解决方案中有不同版本的XF被引用到不同项目中,或者一个.csproj文件引用了旧的.targets文件。

一些手动清理工作应该能够解决这个问题。


谢谢Stephane!手动清理解决了问题。 - Blazey
1
@Blazey 什么是手动清理?是删除 packages 文件夹中的所有内容还是从项目中移除所有包? - Emil
我在记事本中编辑了.csproj文件,并删除了所有旧的XF引用。 - Blazey
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Morgan Touverey Quilling
2
如果您是 Git 用户,可以在项目根目录中运行 git clean -xdf 命令。请确保所有更改都已暂存或提交。 - Kent Boogaart
@MorganTouvereyQuilling,您有关于如何在Mac上进行手动清理的建议吗?我在Visual Studio创建的目录中没有看到命名文件夹。 - Le Mot Juiced

4
如果你的项目依赖于使用XamlC的第三方程序集,并且该程序集已经在XF<2.3.3上构建,你仍然可能会遇到此问题。
有一个修复方法,并将作为XF 2.3.3的第一个服务发布。

0

在我的情况下,我的核心和Android版本上有不同的Xamarin.Forms版本。在所有项目上安装相同的版本可以解决这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接