DEBUG完美地执行 UWP 应用程序。
使用在RELEASE崩溃中编译的完全相同的代码与此错误消息
System.PlatformNotSupportedException:
'Dynamic code generation is not supported on this platform.'
Run Code Online (Sandbox Code Playgroud)
执行此代码时(它使用Dapper 1.5.1and System.Data.SQLite 1.0.109.2)
using (var c = NewConnection())
{
var sql = @"
update settings
set
""value"" = @SetDate
where ""key"" = 'week_date'";
c.Execute(sql, new { SetDate = date }); //<= throws PlatformNotSupportedException
// only on RELEASE not in DEBUG
}
Run Code Online (Sandbox Code Playgroud)
该应用程序是 UWP 配置如下。此外,故障代码是一个.NET Standard 2.0 Class Library
为什么它RELEASE只会崩溃以及如何修复它?
Dapper 非常深入地基于运行时 IL 生成,其方式基本上不可能改变。运行时 IL 生成从根本上与 UWP 不兼容。
没有简单的方法来完成这项工作。
所以:要做到这一点,你需要使用一些类似 dapper-like-but-not-dapper 的东西,以及两种替代实现之一:
也许现在,更实用的方法是:在这种情况下不要使用 dapper。