CARVIEW |
Select Language
HTTP/2 200
date: Thu, 24 Jul 2025 15:50:05 GMT
content-type: text/html; charset=utf-8
cache-control: max-age=0, private, must-revalidate
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
link: ; rel=preload; as=fetch; crossorigin=use-credentials
referrer-policy: no-referrer-when-downgrade
server-timing: issue_layout-fragment;desc="issue_layout fragment";dur=223.035706,issue_conversation_content-fragment;desc="issue_conversation_content fragment";dur=666.300091,issue_conversation_sidebar-fragment;desc="issue_conversation_sidebar fragment";dur=86.468439,nginx;desc="NGINX";dur=1.24507,glb;desc="GLB";dur=100.062043
strict-transport-security: max-age=31536000; includeSubdomains; preload
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With, Accept,Accept-Encoding, Accept, X-Requested-With
x-content-type-options: nosniff
x-frame-options: deny
x-voltron-version: fd8fbbc
x-xss-protection: 0
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=YM6cAFCQOHQYmQPoin9HqQT1x2KAp8SV2a02paATc32LT5gGB10WzashjfIf4Ko1XfiqoHOKBfuFqogjmyBlflpkBm4%2Br7Kk6b4caMz5f6kMFY8S7rEE3bLyzc0%2BHHeKo%2FUW7Kz95noAlE46ozHsPapXuyfYBVgPngi8hKAoxzYBz2wD8Jaa4violQD4HoljZ%2BbyZcDOvgE9byExNQ%2FXD%2B6tbJFqsLj3CjiKkypYB8jjutDrVMADVaSBbUc%2B%2FHebyKENfTLLEfia%2BfUonU%2Brag%3D%3D--06Br1%2Br07d0gMLFx--T%2Fevb950nxRs3Mhkh6I1lQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1150142635.1753372204; Path=/; Domain=github.com; Expires=Fri, 24 Jul 2026 15:50:04 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Fri, 24 Jul 2026 15:50:04 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: E6A8:1EAE79:D6AE1:FA52C:6882562C
FileStream does not work with P/Invoked file descriptor and SafeFileHandle Β· Issue #12783 Β· mono/mono Β· GitHub
No one assignedNo typeNo projectsNo milestoneNone yetNo branches or pull requests
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Description
Steps to Reproduce
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace linuxwriter
{
class Program
{
static void Main()
{
int fd;
try
{
fd = creat("file.txt", Convert.ToInt32("777", 8));
}
catch (Exception exception)
{
throw new Exception($"Error trying to create file: {exception.Message}");
}
if (fd == -1)
{
using (File.Create("file.txt"))
{
// File.Create() should have thrown an exception
}
File.Delete("file.txt");
throw new InvalidOperationException($"libc creat failed, but File.Create did not");
}
var sfh = new SafeFileHandle((IntPtr)fd, ownsHandle: true);
using (var stream = new FileStream(sfh, FileAccess.ReadWrite))
using (var writer = new StreamWriter(stream))
{
writer.WriteLine("Normally a binary file extracted from a zip");
}
}
[DllImport("libc", SetLastError = true)]
private static extern int creat(string pathname, int mode);
}
}
Current Behavior
The file is created with the correct permissions, however, when attempting to use the file descriptor in a FileStream, it crashes with the following error and stack trace:
Unhandled Exception:
System.IO.IOException: Invalid handle to path "[Unknown]"
at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0007f] in <8f2c484307284b51944a1a13a14c0266>:0
at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <8f2c484307284b51944a1a13a14c0266>:0
at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access) [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (Microsoft.Win32.SafeHandles.SafeFileHandle,System.IO.FileAccess)
at linuxwriter.Program.Main () [0x0007c] in <85036eb2b84e47d0aa546e0d393fb85b>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Invalid handle to path "[Unknown]"
at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0007f] in <8f2c484307284b51944a1a13a14c0266>:0
at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <8f2c484307284b51944a1a13a14c0266>:0
at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access) [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (Microsoft.Win32.SafeHandles.SafeFileHandle,System.IO.FileAccess)
at linuxwriter.Program.Main () [0x0007c] in <85036eb2b84e47d0aa546e0d393fb85b>:0
Expected Behavior
Program should write to the file and close the file descriptor before exiting normally. FYI this code works as I expected with .NET Core
On which platforms did you notice this
[x] Linux
I haven't tried Mac, but this is not relevant for Windows as this code is P/Invoking a POSIX method to set permission bits that don't exist in filesystems on Windows.
Version Used:
Mono JIT compiler version 4.6.2 (Debian 4.6.2.7+dfsg-1ubuntu1)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
Stacktrace
see above.
lihop and BCSharp
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Issue actions
You canβt perform that action at this time.