![](/img/trans.png)
[英]How to solve MTOUCH (MT2002) error in Xamarin.iOS with System.Reflection.Emit
[英]ML.Net working on Xamarin.Android but not on Xamarin.iOS: System.Reflection.Emit
我有一个运行 Xamarin.Forms 解决方案的 .NETStandard 2.1 解决方案。 在尝试执行一些 ML 工作(预测异常)时,我仅在 Xamarin.iOS 中遇到运行时异常。
System.PlatformNotSupportedException
带有“此平台不支持操作”的消息。 这是我的代码:
// Dataset for ML
var amounts = new int[] { 100, 150, 200, 300, 250, 3000, 100, 250, 300, 250 };
var withdrawals = amounts.Select(amount => new Withdrawal { Amount = amount }).ToList();
// Instantiate ML context
var mlContext = new Microsoft.ML.MLContext();
// Create you algorithm
var estimator = mlContext.Transforms.DetectIidSpike( // "using ML;" needed for this statement
outputColumnName: nameof(Prediction.Output),
inputColumnName: nameof(Withdrawal.Amount),
confidence: 99,
pvalueHistoryLength: amounts.Length/2);
// Link data to algorithm
var amountsData = mlContext.Data.LoadFromEnumerable(withdrawals); // <=THE LINE THROWING THE EXCEPTION
var transformedAmountsData = estimator.Fit(amountsData).Transform(amountsData);
// Create output
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedAmountsData, reuseRowObject:false).ToList();
foreach (var prediction in predictions)
{
var isAnomaly = prediction.Output[0];
var originalValue = prediction.Output[1];
var confidenceLevel = prediction.Output[2];
Console.WriteLine($"{originalValue} {confidenceLevel} {isAnomaly}");
}
这是两个模型对象:
class Withdrawal
{
public float Amount { get; set; }
}
class Prediction
{
[Microsoft.ML.Data.VectorType]
public double[] Output { get; set; }
}
这是堆栈跟踪:
at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Boolean skipVisibility) [0x00006] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.notsupported.cs:64 \\n at Microsoft.ML.ApiUtils.GeneratePeek[TOwn,TRow,TValue] (System.Reflection.PropertyInfo propertyInfo, System.Reflection.Emit.OpCode assignmentOpCode) [0x00040] in <ac1708cf77ce4a63b733a786896eec8e>:0 \\n at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)\\n at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
我从Xamarin.iOS官方文档中了解到 System.Reflection.Emit 不受支持。 所以我的问题是有什么方法可以使这项工作?
我知道 Jonathan Peppers 的 Xamarin 书, 提到在定义符号字段中使用“NO_LCG”来消除相同的错误并使 Ninject 在 Xamarin.iOS 上工作。 虽然这对这种情况不起作用,但是有没有类似的东西可以解决它?
我不知道你从哪里得到的!
如果您自己执行mtouch
,您会发现许多在标准 Microsoft 指南和“实验性”功能中没有很好记录的选项,这是双重正确的:
mtouch --help
--interpreter[=VALUE] Enable the *experimental* interpreter. Optionally
takes a comma-separated list of assemblies to
interpret (if prefixed with a minus sign, the
assembly will be AOT-compiled instead). 'all'
can be used to specify all assemblies. This
argument can be specified multiple times.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.