New project won't compile - Burst 1.8.2 error: The name 'Unsafe' does not exist

I just downloaded Unity 2021.3.16f1 URP and created a new project. Whilst creating it, a prompt came up and asked me to go into safe mode. The following errors occurred:

Library\PackageCache\com.unity.burst@1.8.2\Runtime\SharedStatic.cs(35,28): error CS0103: The name ‘Unsafe’ does not exist in the current context
Library\PackageCache\com.unity.burst@1.8.2\Runtime\BurstString.Float.cs(1442,21): error CS0103: The name ‘Unsafe’ does not exist in the current context
Library\PackageCache\com.unity.burst@1.8.2\Runtime\BurstString.Float.cs(1469,21): error CS0103: The name ‘Unsafe’ does not exist in the current context
Library\PackageCache\com.unity.burst@1.8.2\Runtime\BurstString.Float.cs(1594,17): error CS0103: The name ‘Unsafe’ does not exist in the current context
Library\PackageCache\com.unity.burst@1.8.2\Runtime\BurstString.Float.cs(1651,17): error CS0103: The name ‘Unsafe’ does not exist in the current context

I don’t think the fault is with the package directly. I had to rollback my Windows 10 to a previous version due to graphics driver failure. I had Unity 2021.3.16f1 installed and rollbacked to a point where I had only 2021.3.11f installed. I think it’s a Windows registry error or something is cached.

I will try to use Unity 2021.3.15f1 to see if it works

Installed 2021.3.15f1 and created a new 3D URP Core project. The above errors are gone. The project works normally.

However, when downgrading my existing project from 2021.3.16f1 to 2021.3.15f1 there are some errors. Would have been good if I had a backup right now. Will try to fix it. If it doesn’t work I’ll just make a new project and import all of my assets.

I’m still trying to fix the project. I tried making a new project and copied all assets but all my presets are gone and the errors persist. I’m currently getting this error when running the game in the editor:

DllNotFoundException: UnityOpenXR assembly: type: member:(null)
UnityEngine.XR.OpenXR.OpenXRLoaderBase.Initialize () (at Library/PackageCache/com.unity.xr.openxr@1.5.3/Runtime/OpenXRLoader.cs:177)
UnityEngine.XR.Management.XRManagerSettings.InitializeLoaderSync () (at Library/PackageCache/com.unity.xr.management@4.2.0/Runtime/XRManagerSettings.cs:190)
UnityEngine.XR.Management.XRGeneralSettings.InitXRSDK () (at Library/PackageCache/com.unity.xr.management@4.2.0/Runtime/XRGeneralSettings.cs:175)
UnityEngine.XR.Management.XRGeneralSettings.AttemptInitializeXRSDKOnLoad () (at Library/PackageCache/com.unity.xr.management@4.2.0/Runtime/XRGeneralSettings.cs:148)

Which leads to DiagnosticReport.StartReport();
I assume I need to reload the OpenXR plugin somehow. I tried to rebuild the solution from Visual Studio but the error is still present.

Any help will be much appreciated

Finally fixed it.

Unity caches packages in “C:\Users\User\AppData\Local\Unity\cache\packages\packages.unity.com”
I deleted the folder “com.unity.xr.openxr@1.5.3” which was 20.2MB at the time.
After I went back into Unity, a new folder with the same name was created with a new size of 28.4MB. Which means the error was with the cached instance of the package.
With this new instance, I restarted Unity and I could run the game without errors. Even my HMD connection works now.

Hope this helps someone

4 Likes

I got the same error with Unity 2022.2.2f1. Even I deleted package cache from users folder and project library folder, I still get this error. How can I fix this?

1 Like

Seeing this as well since 2022.2 came out consistently on OS 10.14. Would be great to be using 2022.2, but this is a show stopper.

yeah, it is still happening even in Unity 2022.2.7f1

It looks like Unity has iterated on C# in 2222.2 such that Unsafe dll support that previously worked no longer does. However it appears that a newer version of Unsafe should be used instead.

If you’re like me and not interested in dealing with nuget, rename the .nuget download to .zip, unzip it, and move lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll into your Assets dir.

I did the Unity 2022.2 upgrade from there.

Hi, I was able to solve this issue also by upgrading Burst package to 1.8.3 and restart the editor.

2 Likes

I am using unity 2022.3.6f1 and whenever i tried to open a 3D URP project is asks to enable to safe mode and pops up with too many errors how can i fix that i tried to find solution but can’t find nay please help…

Maybe my answer will help someone.
You need to manually register it in the manifest.json - Unity NuGet.

https://github.com/netpyoung/unity.webp/issues/52

1 Like

I learned to address this:

  1. Open the Package Manager
  2. select “Packages: Unity Registry” from the top left popup
  3. add “Collections”

(this is likely why updating Burst works since it updates the Collections package)