.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 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.Collections.ConcurrentSystem.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 . The following table lists the APIs with limitations.
ThreadPoolClass | Status | Notes |
|---|---|---|
| DriveInfo | Not supported | All methods throw |
| FileStream | Partially supported | All synchronous operations work. Async methods cause an unrecoverable browser hang. |
| FileSystemAclExtensions | Not supported | Windows-only. All methods throw |
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 , and , which provide real hardware semantics inside Burst-compiled jobs.
InterlockedThread.MemoryBarrierVolatileThe following table lists the APIs with limitations.
Class | Status | Notes |
|---|---|---|
| CancellationTokenSource | Partially supported | The timeout mechanism doesn't work because it relies on |
| CompressedStack | Not supported | All methods throw |
| EventWaitHandle | Not supported | Named event handles throw |
| HostExecutionContextManager | Not supported | All methods throw |
| Interlocked | Partially supported | The method executes without effect in managed code, but provides real hardware semantics inside Burst-compiled jobs. |
| Monitor | Not supported | Other methods execute but have no effect. |
| Mutex | Not supported | Named mutexes throw |
| Semaphore | Not supported | Named semaphores throw |
| Thread | Not supported | Can be constructed. |
| Thread.MemoryBarrier | Partially supported | The method executes without effect in managed code, but provides real hardware semantics inside Burst-compiled jobs. |
| ThreadPool | Not supported | |
| Timer | Not supported | Doesn't work because it relies on |
| Volatile | Partially supported | The 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 namespace function correctly:
System.Threading.TasksValueTaskValueTask<T>TaskCompletionSource<T>- Synchronous factory methods such as and
Task.FromResult.Task.CompletedTask
All APIs that schedule work through the cause an unrecoverable browser hang. Use for asynchronous programming because it has lower memory overhead than .
ThreadPoolAwaitableTaskThe following table lists the APIs with limitations.
Class | Status | Notes |
|---|---|---|
| Parallel | Not supported | All methods ( |
| Task.Delay | Not supported | Causes an unrecoverable browser hang. The internal timer doesn't fire. |
| Task.Run | Not supported | Causes an unrecoverable browser hang. Schedules work through |
| TaskFactory / TaskFactory<T> | Not supported | |
System.Timers
System.Timers.TimerElapsedSystem.Net and System.Net.Http
The following data classes in the and namespaces function correctly:
System.NetSystem.Net.HttpCookieWebHeaderCollectionSocketAddressHttpRequestMessageStringContentMultipartContent
HttpListenerThe following classes aren't implemented and cause an unrecoverable browser hang:
HttpClientWebClientHttpWebRequestFileWebRequest
Use UnityWebRequest as an alternative for HTTP requests.
System.Net.Security
SslStreamNegotiateStreamSystem.Net.Sockets
The browser sandbox doesn't expose POSIX sockets. Only pure data types such as and work.
LingerOptionSocketExceptionAs 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