C#/Mono - 内存映射文件问题

标签 c# mono arm beagleboneblack

编辑:我已经将 mono(必须使用 these instructions 从源代码编译)更新到版本 3.2.7。我不再收到提示容量过载参数的错误,现在我收到以下错误。以前,当使用 mono verison 2.1 时,我可以打开一个小文本文件作为内存映射文件作为测试。使用新版本的单声道,无论我试图打开什么文件/提供或遗漏哪个重载参数,我都会遇到同样的错误。快速谷歌搜索没有产生任何结果,所以我回到你身边,stackoverflow。我该怎么办?

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd () at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at System.IO.MemoryMappedFiles.MemoryMapImpl.Open (System.String path, FileMode mode, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, FileMode mode, System.String mapName, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path) [0x00000] in <filename unknown>:0 at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd () at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at System.IO.MemoryMappedFiles.MemoryMapImpl.Open (System.String path, FileMode mode, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, FileMode mode, System.String mapName, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path) [0x00000] in <filename unknown>:0 at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

我正在从事一个涉及控制 beaglebone 上的 GPIO 引脚的项目。我正在尝试将一些 python 代码移植到 C#(一种我不太熟悉的语言)中,但在尝试打开位于/dev/mem 的板上的寄存器作为内存映射文件时遇到了问题,就像我在 python 中所做的那样.我正在使用 .Net 框架版本 4.0.30319 在 vi​​sual studio 2010 中编写和编译代码,并使用带有编译器版本 2.10.8.1 的单声道在 ubuntu 中运行它。

精简代码如下:

long offset = 0x4804c000;
long length = 0xfff;
using (var mm0 = MemoryMappedFile.CreateFromFile(@"/dev/mem", FileMode.Open, 
                 "gpio1", capacity))
{
    using (var accessor = mm0.CreateViewAccessor(offset, length))
    {
    do stuff
    }
}

这会产生以下错误:

Unhandled Exception: System.ArgumentException: capacity at System.IO.MemoryMappedFiles.MemoryMapImpl.Open (System.String path, FileMode mode, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, FileMode mode, System.String mapName, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, FileMode mode, System.String mapName, Int64 capacity) [0x00000] in <filename unknown>:0 at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: capacity at System.IO.MemoryMappedFiles.MemoryMapImpl.Open (System.String path, FileMode mode, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, FileMode mode, System.String mapName, Int64 capacity, MemoryMappedFileAccess access) [0x00000] in <filename unknown>:0 at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile (System.String path, FileMode mode, System.String mapName, Int64 capacity) [0x00000] in <filename unknown>:0 at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

我试过指定和不指定内存映射的容量,以及许多不同的容量值,从几兆字节到板上的整个可用内存。有人知道从这里去哪里的提示吗?

最佳答案

Mono 2.10 非常旧,请升级。

关于C#/Mono - 内存映射文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21654905/

相关文章:

c# - 为什么一路往下用Async/await

c# - 如何调用分配输出缓冲区以在 C# 中返回数据的非托管 C++ 函数?

c# - 使用for循环读取完整的文本文件

c# - System.Diagnostics.Process 实例可以被垃圾收集吗?

android - 在 Android : "not found" 上安装预构建的二进制文件

arm - ARM CMSIS DSP fft 函数的正确 FFT 长度

linux - 适用于 Linux 操作系统的开源 VS 专有 ARM 调试器

c# - 正则表达式 C# - 是否可以在匹配时提取匹配项?

c# - 如何使用 Mono.Security 设置 X509 SubjectAltName (SAN)?

c# - 如何为 C# 编写 makefile?