折腾记: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跑,报错果然没有了。说明确实是版本太高不支持造成的。


(这里是文档结束)

相关推荐
Zhen (Evan) Wang1 小时前
.NET 6 API使用Serilog APM
c#·.net
武藤一雄3 小时前
[.NET] 中 System.Collections.Generic命名空间详解
windows·微软·c#·asp.net·.net·.netcore
军训猫猫头3 小时前
3.NModbus4 长距离多设备超时 C# + WPF 完整示例
c#·.net·wpf·modbus
Aevget5 小时前
DevExpress WPF中文教程:Data Grid - 如何绑定到有限制的自定义服务(一)?
ui·.net·wpf·devexpress·ui开发·wpf界面控件
ONLYOFFICE5 小时前
如何在Windows ARM64 上安装ONLYOFFICE桌面编辑器:完整指南
编辑器·arm·onlyoffice
唐青枫5 小时前
告别频繁 GC:C#.NET PooledList 的设计与使用场景
c#·.net
Bigan(安)18 小时前
【奶茶Beta专项】【LVGL9.4源码分析】09-core-obj_class对象类系统
linux·c语言·mcu·arm·unix
SEO-狼术19 小时前
FastReport .NET Mono 2026
.net
Bigan(安)19 小时前
【奶茶Beta专项】【LVGL9.4源码分析】08-theme主题管理
linux·c语言·mcu·arm·unix