欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > 折腾记:arm上的mono和.net

折腾记:arm上的mono和.net

2024/10/24 11:30:54 来源:https://blog.csdn.net/2301_77171572/article/details/143184528  浏览:    关键词:折腾记:arm上的mono和.net

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

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

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

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


        继续折腾mono和.net。

目录

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

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

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

生成.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新增功能来测试:

//.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执行失败:

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执行成功:

root@ubuntu:~# ./dotnet ConsoleApp.dll
.net8
root@ubuntu:~#

生成.net core 3.1程序测试

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

    <ImplicitUsings>disable</ImplicitUsings>

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

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


(这里是文档结束)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com