避免.NET本机错误 [英] Avoid .NET Native bugs

查看:83
本文介绍了避免.NET本机错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了去年的时间(兼职)将现有的(成功的)Windows 8.1应用程序迁移到Windows 10 UWP。现在,就在将其发布到商店之前,我在发布构建模式(触发.NET Native)中测试了该应用程序。一切似乎都有效,直到我偶然地注意到了一个细微但严重的(由于数据损坏)错误。我花了两天时间将其简化为以下三行代码:

I spent the last year (part time) to migrate my existing (and successful) Windows 8.1 app to Windows 10 UWP. Now, just before releasing it to the store, I tested the app in the "Release" build mode (which triggers .NET Native). Everything seemed to work until I - by chance - noted a subtle but serious (because data-compromising) bug. It took me two days to reduce it to these three lines of code:

var array1 = new int[1, 1];
var array2 = (int[,])array1.Clone();
array2[0, 0] = 666;

if (array1[0, 0] != array2[0, 0]) {
    ApplicationView.GetForCurrentView().Title = "OK.";
} else {
    ApplicationView.GetForCurrentView().Title = "Bug.";
}

在调试模式下,克隆二维数组意味着修改一个数组项不会影响另一个数组。在发布模式下,修改一个阵列也会更改另一个阵列。 (我正在使用最新的VS 2017。)

In Debug mode, cloning the 2D array means modifying one array item does not affect the other array. In Release mode, modifying one array changes the other, too. (I am using the latest VS 2017.)

现在,我意识到使用.NET Native 1.6(在VS 2017中不是默认值)可以解决此特定问题。

Now, I realized that using .NET Native 1.6 (which is not the default in VS 2017), solves this particular issue.

但是我对.NET Native失去了信心。 .NET Native仍在我的应用程序中引入了多少个错误?我的Windows 8.1应用程序无需.NET Native,即可快速,平稳地运行。那么,为什么我必须使用似乎充满错误的.NET Native? (最近两天我就知道了很多.NET Native错误。)

But I lost the faith in .NET Native. How many bugs are still introduced by .NET Native into my app? My Windows 8.1 app runs fast and smoothly without .NET Native. So why should I have to use .NET Native which seems to be full of bugs? (I got to know a lot of .NET Native bugs in the last two days.)

最近,项目 UWP Desktop Bridge允许将传统的桌面应用发布到App Store(他们不必使用.NET Native)。那么为什么我必须使用.NET Native?

Recently, project "UWP Desktop Bridge" has allowed to publish traditional desktop apps to the App Store (they do not have to use .NET Native). So why do I have to use .NET Native?

有没有一种方法可以完全跳过.NET Native?如果没有,我是否可以配置.NET Native编译器使其行为不那么具有破坏性?

Is there a way to skip .NET Native totally? If not, can I configure the .NET Native compiler to behave not so destructive?

推荐答案

这可能是.NET上的错误。 NET Native工具链...

That might be a bug on the .NET Native tool chain...

根据我的测试, Array.Copy 可以按预期工作:

From my tests, Array.Copy works as expected:

var array1 = new int[1, 1];
var array2 = new int[1, 1];
Array.Copy(array1, array2, array1.Length);
array2[0, 0] = 666;

if (array1[0, 0] != array2[0, 0])
{
    ApplicationView.GetForCurrentView().Title = "OK.";
}
else
{
    ApplicationView.GetForCurrentView().Title = "Bug.";
}

这篇关于避免.NET本机错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆