Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


.NET API support on the Web platform

Understand the limitations of .NET APIs on the Web platform, including unsupported namespaces and alternatives.
Read time 4 minutesLast updated 12 days ago

The Web platform supports most of the .NET API, but some APIs have limitations due to browser security restrictions, the absence of managed threading, and the lack of raw network socket access.

System.Collections.Concurrent

All containers in
System.Collections.Concurrent
compile on the Web platform, but they lack real thread safety. Unity replaces the synchronization primitives in these containers with empty functions. Use the Collections package as an alternative for Burst-compiled jobs.

System.IO

Most file I/O works through Emscripten's in-memory virtual file system (MEMFS). Asynchronous I/O APIs don't work because they are backed by the
ThreadPool
. The following table lists the APIs with limitations.

Class

Status

Notes

DriveInfoNot supportedAll methods throw
NotSupportedException
.
FileStreamPartially supportedAll synchronous operations work. Async methods cause an unrecoverable browser hang.
FileSystemAclExtensionsNot supportedWindows-only. All methods throw
NotSupportedException
.

System.Threading

Because the Web platform doesn't support managed threading, most APIs in this namespace have limited functionality. Synchronization primitives compile and execute without throwing, but their threading behavior has no effect. The only exceptions are
Interlocked
,
Thread.MemoryBarrier
and
Volatile
, which provide real hardware semantics inside Burst-compiled jobs.
The following table lists the APIs with limitations.

Class

Status

Notes

CancellationTokenSourcePartially supportedThe timeout mechanism doesn't work because it relies on
Timer
.
CompressedStackNot supportedAll methods throw
NotSupportedException
.
EventWaitHandleNot supportedNamed event handles throw
NotSupportedException
. Other methods execute but have no effect.
HostExecutionContextManagerNot supportedAll methods throw
NotImplementedException
.
InterlockedPartially supportedThe method executes without effect in managed code, but provides real hardware semantics inside Burst-compiled jobs.
MonitorNot supportedOther methods execute but have no effect.
MutexNot supportedNamed mutexes throw
NotSupportedException
. Other methods execute but have no effect.
SemaphoreNot supportedNamed semaphores throw
NotSupportedException
. Other methods execute but have no effect.
ThreadNot supportedCan be constructed.
Start()
doesn't throw, but thread delegates don't execute.
Join
,
Priority
(set), and
DisableComObjectEagerCleanup
fail.
Thread.MemoryBarrierPartially supportedThe method executes without effect in managed code, but provides real hardware semantics inside Burst-compiled jobs.
ThreadPoolNot supported
QueueUserWorkItem
and
UnsafeQueueUserWorkItem
accept calls but callbacks never execute.
TimerNot supportedDoesn't work because it relies on
ThreadPool
.
VolatilePartially supportedThe method executes without effect in managed code, but provides real hardware semantics inside Burst-compiled jobs.

System.Threading.Tasks

The following types and methods in the
System.Threading.Tasks
namespace function correctly:
  • ValueTask
  • ValueTask<T>
  • TaskCompletionSource<T>
  • Synchronous factory methods such as
    Task.FromResult
    and
    Task.CompletedTask
    .
All APIs that schedule work through the
ThreadPool
cause an unrecoverable browser hang. Use
Awaitable
for asynchronous programming because it has lower memory overhead than
Task
.
The following table lists the APIs with limitations.

Class

Status

Notes

ParallelNot supportedAll methods (
For
,
ForEach
,
Invoke
) cause an unrecoverable browser hang.
Task.DelayNot supportedCauses an unrecoverable browser hang. The internal timer doesn't fire.
Task.RunNot supportedCauses an unrecoverable browser hang. Schedules work through
ThreadPool
.
TaskFactory / TaskFactory<T>Not supported
StartNew
,
ContinueWhenAll
, and
ContinueWhenAny
all cause an unrecoverable browser hang.

System.Timers

System.Timers.Timer
doesn't work on the Web platform because the
Elapsed
event relies on the thread pool mechanism, which doesn't function.

System.Net and System.Net.Http

The following data classes in the
System.Net
and
System.Net.Http
namespaces function correctly:
  • Cookie
  • WebHeaderCollection
  • SocketAddress
  • HttpRequestMessage
  • StringContent
  • MultipartContent
HttpListener
isn't supported because it isn't possible to run a web server inside a browser.
The following classes aren't implemented and cause an unrecoverable browser hang:
  • HttpClient
  • WebClient
  • HttpWebRequest
  • FileWebRequest
Use UnityWebRequest as an alternative for HTTP requests.

System.Net.Security

SslStream
and
NegotiateStream
aren't supported. Configuration option classes work.

System.Net.Sockets

The browser sandbox doesn't expose POSIX sockets. Only pure data types such as
LingerOption
and
SocketException
work.
As an alternative, use the browser's WebSocket or WebRTC APIs through a JavaScript plug-in. Another option is the Emscripten POSIX socket implementation, which proxies socket operations through a WebSocket-based relay server to connect to real socket ports on non-web clients or servers.

System.Net.WebSockets

ClientWebSocket
isn't supported. Use the browser's WebSocket API directly through a JavaScript plug-in or a third-party plug-in.

Additional resources