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


(这里是文档结束)

相关推荐
bicijinlian11 小时前
.Net HttpClient 使用代理功能
c#·.net·httpclient·.net httpclient·httpclient 代理
界面开发小八哥18 小时前
界面控件DevExpress WinForms v24.2 - 数据处理功能增强
.net·界面控件·devexpress·ui开发·winforms
CloudPilotAI1 天前
“海外滴滴”Uber的Arm迁移实录:重构大规模基础设施
arm开发·架构·arm
码观天工1 天前
【.NET必读】RabbitMQ 4.0+重大变更!C#开发者必须掌握的6大升级要点
c#·rabbitmq·.net·mq
o0向阳而生0o1 天前
43、Server.UrlEncode、HttpUtility.UrlDecode的区别?
c#·.net
Kookoos1 天前
【实战】基于 ABP vNext 构建高可用 S7 协议采集平台(西门子 PLC 通信全流程)
后端·物联网·c#·.net
焚 城2 天前
.NET8关于ORM的一次思考
后端·.net
bicijinlian2 天前
.Net HttpClient 管理客户端(初始化与生命周期管理)
c#·.net·httpclient·.net httpclient·c# http
o0向阳而生0o2 天前
42、在.NET 中能够将⾮静态的⽅法覆写成静态⽅法吗?
c#·.net
bicijinlian2 天前
.Net HttpClient 使用准则
.net·httpclient·.net httpclient·c# httpclient·c# http请求