Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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# 在Windows Server 2016中读取MIME类型时发生AccessViolationException异常_C#_Mime Types_Dllimport_Access Violation_Windows Server 2016 - Fatal编程技术网

C# 在Windows Server 2016中读取MIME类型时发生AccessViolationException异常

C# 在Windows Server 2016中读取MIME类型时发生AccessViolationException异常,c#,mime-types,dllimport,access-violation,windows-server-2016,C#,Mime Types,Dllimport,Access Violation,Windows Server 2016,我的一些产品代码在从Windows 2008R2服务器移动到Windows 2016服务器时被破坏。代码检查文件扩展名与文件中嵌入的MIME类型不匹配的文件 为了获得嵌入的MIME类型,我们使用。(缓冲区是从正在扫描的文件中读取的数据。) 我已经验证了mimeType被设置为非零数。 周末有两件事改变了密码被破解了: 应用程序已从Windows Server 2008R2计算机移动到Windows Server 2016 我们从中下载文件的(外部控制的)web服务已更新 Windows 2016

我的一些产品代码在从Windows 2008R2服务器移动到Windows 2016服务器时被破坏。代码检查文件扩展名与文件中嵌入的MIME类型不匹配的文件

为了获得嵌入的MIME类型,我们使用。(缓冲区是从正在扫描的文件中读取的数据。)

我已经验证了mimeType被设置为非零数。 周末有两件事改变了密码被破解了:

  • 应用程序已从Windows Server 2008R2计算机移动到Windows Server 2016
  • 我们从中下载文件的(外部控制的)web服务已更新
  • Windows 2016安全性是否以某种方式破坏了此功能?是否有其他方法可以扫描嵌入的MIME类型

                public static string ScanBufferForMimeType(byte[] buffer)
                {
                    uint mimeType = default(uint);
                    FindMimeFromData(0, null, buffer, 256, null, 0, ref mimeType, 0);
                    IntPtr mimeTypePtr = new IntPtr(mimeType);
                    string mime = Marshal.PtrToStringUni(mimeTypePtr); //AccessViolationException is thrown here.
                    Marshal.FreeCoTaskMem(mimeTypePtr);  
                    if (string.IsNullOrEmpty(mime))
                        mime = "application/octet-stream";
                    return mime;
                }