折腾记:arm上的mono和.net

初级代码游戏的专栏介绍与文章目录-CSDN博客

我的github:codetoys,所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。

这些代码大部分以Linux为目标但部分代码是纯C++的,可以在任何平台上使用。

源码指引:github源码指引_初级代码游戏的博客-CSDN博客


继续折腾mono和.net

目录

源码编译的不能用,直接安装的没问题

怀疑版本支持问题,下载.net8运行时

验证.net8新增功能(不支持的一定会报错)

[生成.net core 3.1程序测试](#生成.net core 3.1程序测试)


好不容易把mono源码编译出来了,拿到设备上,发现缺东西啊:

复制代码
The assembly mscorlib.dll was not found or could not be loaded.

源码编译的不能用,直接安装的没问题

坑啊,先不折腾了,直接安装标准环境(这个设备是标准Ubuntu),装好就能用了。

在visual studio上生成一个C#控制台项目,.net8,用mono(标准环境,我自己编译的始终不行)执行:

复制代码
root@ubuntu:~# mono ConsoleApp.dll
Can't find custom attr constructor image: /root/ConsoleApp.dll mtoken: 0x0a00000c due to: Could not resolve type with token 0100000e from typeref (expected class 'System.Runtime.CompilerServices.NullableContextAttribute' in assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Runtime.CompilerServices.NullableContextAttribute member:(null)
Hello, World!
root@ubuntu:~#

报了一个错,然后后面正常输出了。这说明程序能跑,但是有问题。

怀疑版本支持问题,下载.net8运行时

怀疑是版本支持问题,下载.net运行时来看看。

下载arm64的.net8 runtime:dotnet-runtime-8.0.10-linux-arm64.tar.gz

注意,解压缩后直接释放到了当前目录,不是在没有子目录下,还好我这个目录下啥也没有,只有测试程序。

然后运行"./dotnet ConsoleApp.dll"执行正常,这说明确实是版本问题。

验证.net8新增功能(不支持的一定会报错)

为了明确验证,我专门找了一个.net8新增功能来测试:

cs 复制代码
//.net8新增接口TimeProvider(使用.net core 3.1会提示找不到)
	class MockTimeProvider : TimeProvider
	{
		public MockTimeProvider()
		{
		}

		public override DateTimeOffset GetUtcNow()
		{
			return new DateTimeOffset();
		}

		public override TimeZoneInfo LocalTimeZone => TimeZoneInfo.Utc;
	}
//程序调用:
			var b = new MockTimeProvider();
			Console.WriteLine(".net8");
//发布为可移植包

把这点代码添到项目里面,重新发布。

用mono执行失败:

cs 复制代码
root@ubuntu:~# mono ConsoleApp.dll
Can't find custom attr constructor image: /root/ConsoleApp.dll mtoken: 0x0a00000c due to: Could not resolve type with token 0100000d from typeref (expected class 'System.Runtime.CompilerServices.NullableContextAttribute' in assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Runtime.CompilerServices.NullableContextAttribute member:(null)

Unhandled Exception:
System.TypeLoadException: Could not resolve type with token 0100000f from typeref (expected class 'System.TimeProvider' in assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not resolve type with token 0100000f from typeref (expected class 'System.TimeProvider' in assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
root@ubuntu:~#

用dotnet执行成功:

cs 复制代码
root@ubuntu:~# ./dotnet ConsoleApp.dll
.net8
root@ubuntu:~#

生成.net core 3.1程序测试

visual studio 2022现在只有.net8了,把项目改成.net core 3.1,提示需要安装,安装后vs自动重启,然后编译不过去了,全局using不支持(在自动生成的文件里,所以修改是没用的),解决方法是修改项目配置文件,项目上右键"编辑项目文件":

cs 复制代码
    <ImplicitUsings>disable</ImplicitUsings>

上面这个改成disable就可以了。

拿这个程序用mono跑,报错果然没有了。说明确实是版本太高不支持造成的。


(这里是文档结束)

相关推荐
半亩码田4 小时前
【.NET新特性·第8篇】.NET 9 AI 构建基块:Microsoft.Extensions.AI
人工智能·microsoft·.net
Ctrl+Z侠20 小时前
.NET WebApi Windows / Linux Docker 全链路压测与瓶颈定位 0 到 1 教程
linux·windows·.net
慧都小妮子1 天前
Aspose.CAD for .NET 26.6 更新发布
pdf·.net·3d渲染·cad·pdf导出·ifc编辑
夜莺悠吟1 天前
关于对 C# 中 ImplicitUsings,GlobalUsings 的讨论
c#·.net
m0_715646762 天前
20260720
linux·arm
Dlrb12112 天前
ARM--IMX6ULL的SDK学习,BSP开发工程管理,以及链接脚本与Makefile的编写
单片机·嵌入式硬件·arm·sdk·链接脚本·i.mx6ull·cortex-a7
fen_fen2 天前
麒麟 Linux aarch64安装.NET 6,并适配.net应用(达梦数据库)
linux·服务器·.net
凉、介3 天前
Virtio(三):Virtqueue 建立与 Buffer 提交
笔记·学习·嵌入式·arm·虚拟化·virtio