Skip to content

System.IO.Directory.CreateTempSubdirectory(String prefix) fails with Success exception in wasi-wasm build #92336

Open
@dbaeumer

Description

@dbaeumer

Description

Calling System.IO.Directory.CreateTempSubdirectory(String prefix) fails with an exception in a wasi-wasm build

Reproduction Steps

  • .Net version 8.0.100-rc.1.23455.8
  • tempDir.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
    <OutputType>Exe</OutputType>
    <PublishTrimmed>true</PublishTrimmed>
    <WasmSingleFileBundle>true</WasmSingleFileBundle>
  </PropertyGroup>
</Project>
  • Program.cs
using System;
using System.IO;
using System.Text;

Console.WriteLine("Hello, Wasi Console!");

using (var writer = File.Create("/tmp/test.txt")) {
	writer.Write(Encoding.UTF8.GetBytes("Hello World!"));
}

var dir = Directory.CreateTempSubdirectory();
Console.WriteLine("Created temp dir: " + dir.FullName);
  • dotnet build
  • create a tmp directory in the workspace directory
  • wasmtime 12.0.2
  • run wasmtime run --mapdir /::. --env TMPDIR=/tmp obj/Debug/net8.0/wasi-wasm/wasm/for-build/tempDir.wasm

Expected behavior

Creating the temp directory works

Actual behavior

System.IO.IOException: Success
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Interop.ThrowIOExceptionForLastError()
   at System.IO.Directory.CreateTempSubdirectoryCore(String prefix)
   at System.IO.Directory.CreateTempSubdirectory(String prefix)
   at Program.<Main>$(String[] args)

The write to the file happened successful.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmWebAssembly architecturearea-System.IOblockedIssue/PR is blocked on something - see commentsos-wasiRelated to WASI variant of arch-wasm

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions