Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DllImport(“msvcrt.dll”)在linux上运行时不工作_C#_.net_Linux_Docker_Core - Fatal编程技术网

C# DllImport(“msvcrt.dll”)在linux上运行时不工作

C# DllImport(“msvcrt.dll”)在linux上运行时不工作,c#,.net,linux,docker,core,C#,.net,Linux,Docker,Core,我想用下面的代码比较使用memcmp函数的2字节数组 [DllImport("msvcrt.dll",EntryPoint = "memcmp", CallingConvention = CallingConvention.Cdecl)] static extern int memcmp(byte[] b1, byte[] b2, long count); 当我在Windows上运行应用程序时,它工作正常。但当我在Linux上运行它时,会出现以下异常 Unable to load shar

我想用下面的代码比较使用memcmp函数的2字节数组

[DllImport("msvcrt.dll",EntryPoint = "memcmp", CallingConvention = CallingConvention.Cdecl)]
  static extern int memcmp(byte[] b1, byte[] b2, long count);
当我在Windows上运行应用程序时,它工作正常。但当我在Linux上运行它时,会出现以下异常

Unable to load shared library 'msvcrt.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libmsvcrt.dll: cannot open shared object file: No such file or directory
下面是docker文件

FROM microsoft/dotnet:2.2-sdk AS build-env
WORKDIR /app

COPY *.csproj ./
COPY NuGet.Config ./
RUN dotnet restore

# copy everything else and build
COPY . ./

RUN dotnet publish -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.2-runtime

WORKDIR /app
COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "XXX.dll", "YYY.dll"]

请告诉我应该使用什么?

在Linux上不能只使用“windows”DLL。仅仅因为您在Linux上有一个.NET核心运行时,并不意味着您可以从其他平台/操作系统使用其他库/可执行文件

您应该找到一些其他代码,它们可以比较两字节数组,或者将windows作为底层操作系统


看看这里:

@Damien\u异教徒。谢谢你的帮助。 我使用了下面的代码

 if (((ReadOnlySpan<byte>)slice).SequenceCompareTo((ReadOnlySpan<byte>)masterSlice) == 0)
                    isEqual = true;
if((ReadOnlySpan)切片).SequenceCompareTo((ReadOnlySpan)主切片)==0)
等质量=真;

恕我直言,从.net应用程序调用外部dll以比较两个字节数组似乎有点愚蠢。为了提高性能,我需要使用此函数。看起来它真的希望是以“ms”开头的名称可疑,看起来像Microsoft dll,因此它是特定于平台的(仅限windows)@500 InternalServerError告诉npm社区/javascript-'developers',我使用了foor循环、序列相等、结构相等,最后我选择了memcmp,它与所有人相比具有良好的性能。有人能告诉我如何在linux上使用等效的dll吗。我认为libc.so可以使用,但不知道如何在代码中实现它。这是添加到docker文件中的东西吗?@vaishalikhatri根据所获得的知识,我想你可以在卡住时编写一个新的SO问题。你可以PInvoke libc.SO库。检查