UnityEditor.dll assembly is referenced by user code, but this is not allowed
When building the apk, I am getting this error,
Which script reference to it, how can I know it?
There are a lot of script that contains using UnityEditor
UnityEditor.dll assembly is referenced by user code, but this is not allowed
When building the apk, I am getting this error,
Which script reference to it, how can I know it?
There are a lot of script that contains using UnityEditor
You can’t use that namespace in a build.
Use conditional compilation to remove it (AND remove all the code that uses that namespace obviously).
#if UNITY_EDITOR
using UnityEditor;
#endif
OR…
Put the file into an Editor folder.
Hey so I’ve been running into the same error and tried updating to current 2022.1.16f1 to see if any of those IL2CPP fixes since 1.11 covered it - I also boxed out 120 different scripts with conditional compile. No dice. Not sure what else I could check on when trying to build to iOS.
Here’s a log I’m getting from an attempted iOS build with the same error:
Doesn’t tell me too much about what stopped it, unfortunately
UnityEditor.dll assembly is referenced by user code, but this is not allowed.
#0 GetStacktrace(int)
#1 DebugStringToFile(DebugStringToFileData const&)
#2 DebugLogHandler_CUSTOM_Internal_Log(LogType, LogOption, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)
#3 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
#4 (Mono JIT Code) [DebugLogHandler.cs:10] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[ ])
#5 (Mono JIT Code) [Logger.cs:61] UnityEngine.Logger:Log (UnityEngine.LogType,object)
#6 (Mono JIT Code) [Debug.bindings.cs:130] UnityEngine.Debug:LogError (object)
#7 (Mono JIT Code) [BeeBuildPostprocessor.cs:462] UnityEditor.Modules.BeeBuildPostprocessor:UnityLinkerResultProcessor (Bee.BeeDriver.NodeResult)
#8 (Mono JIT Code) [BeeBuildPostprocessor.cs:510] UnityEditor.Modules.BeeBuildPostprocessor:ReportBuildResults (Bee.BeeDriver.BeeDriverResult)
#9 (Mono JIT Code) [BeeBuildPostprocessor.cs:620] UnityEditor.Modules.BeeBuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs)
#10 (Mono JIT Code) [iOSBuildPostprocessor.cs:510] UnityEditor.iOS.iOSBuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs)
#11 (Mono JIT Code) [DefaultBuildPostprocessor.cs:32] UnityEditor.Modules.DefaultBuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs,UnityEditor.BuildProperties&)
#12 (Mono JIT Code) [PostprocessBuildPlayer.cs:371] UnityEditor.PostprocessBuildPlayer:Postprocess (UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,string,string,string,int,int,UnityEditor.BuildOptions,UnityEditor.RuntimeClassRegistry,UnityEditor.Build.Reporting.BuildReport)
#13 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_int_int_int_object_object_object_int_int_int_object_object (object,intptr,intptr,intptr)
#14 mono_jit_runtime_invoke
#15 do_runtime_invoke
#16 mono_runtime_invoke
#17 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
#18 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
#19 CallMono(char const*, char const*, char const*, ScriptingArguments const&)
#20 DoBuildPlayer(BuildPlayerSetup const&, dynamic_array<EditorSceneBackup, 0ul>&, core::basic_string<char, core::StringStorageDefault<char> >, dynamic_array<core::basic_string<char, core::StringStorageDefault<char> >, 0ul> const&, bool, BuildReporting::BuildReport&, BuildReporting::BuiltAssetBundleInfo*, core::basic_string<char, core::StringStorageDefault<char> > const&)
#21 BuildPlayer(BuildPlayerSetup const&, BuildReporting::BuildReport&)
#22 BuildPipeline_CUSTOM_BuildPlayerInternalNoCheck(ScriptingBackendNativeArrayPtrOpaque*, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeStringPtrOpaque*, BuildTargetPlatformGroup, BuildTargetPlatform, int, BuildPlayerOptions, ScriptingBackendNativeArrayPtrOpaque*, unsigned char)
#23 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck (string[ ],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,UnityEditor.BuildOptions,string[ ],bool)
#24 (Mono JIT Code) [BuildPlayerWindowBuildMethods.cs:169] UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
#25 (Mono JIT Code) [BuildPlayerWindowBuildMethods.cs:95] UnityEditor.BuildPlayerWindow:CallBuildMethods (bool,UnityEditor.BuildOptions)
#26 (Mono JIT Code) [BuildPlayerWindow.cs:1186] UnityEditor.BuildPlayerWindow/<>c__DisplayClass46_0:<GUIBuildButtons>b__0 ()
#27 (Mono JIT Code) [GenericMenu.cs:127] UnityEditor.GenericMenu:CatchMenu (object,string[ ],int)
#28 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object_object_int (object,intptr,intptr,intptr)
#29 mono_jit_runtime_invoke
#30 do_runtime_invoke
#31 mono_runtime_invoke
#32 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
#33 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
#34 CustomPopupMenuInterface::Execute(MenuItem const&)
#35 MenuController::ExecuteMenuItem(MenuItem&, MenuController::ExecutionCause)
#36 -[CocoaMainMenu executeStandard:]
#37 -[NSApplication(NSResponder) sendAction:to:from:]
#38 -[NSMenuItem _corePerformAction]
#39 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:]
#40 -[NSMenu performActionForItemAtIndex:]
#41 -[NSMenu _internalPerformActionForItemAtIndex:]
#42 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:]
#43 NSSLMMenuEventHandler
#44 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*)
#45 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*)
#46 SendEventToEventTarget
#47 SendHICommandEvent(unsigned int, HICommand const*, unsigned int, unsigned int, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**)
#48 SendMenuCommandWithContextAndModifiers
#49 SendMenuItemSelectedEvent
#50 FinishMenuSelection(SelectionData*, MenuResult*, MenuResult*)
#51 PopUpMenuSelectCore(MenuData*, Point, double, Point, unsigned short, unsigned int, unsigned int, Rect const*, unsigned short, unsigned int, Rect const*, Rect const*, __CFDictionary const*, __CFString const*, OpaqueMenuRef**, unsigned short*)
#52 _HandlePopUpMenuSelection8(OpaqueMenuRef*, OpaqueEventRef*, unsigned int, Point, unsigned short, unsigned int, unsigned int, Rect const*, unsigned short, Rect const*, Rect const*, __CFDictionary const*, __CFString const*, OpaqueMenuRef**, unsigned short*)
#53 _HandlePopUpMenuSelectionWithDictionary
#54 SLMPerformPopUpCarbonMenu
#55 _NSSLMPopUpCarbonMenu3
#56 -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:]
#57 -[NSPopUpButtonCell trackMouse:inRect:ofView:untilMouseUp:]
#58 ShowDelayedContextMenu(bool)
#59 GUIView::OnInputEvent(InputEvent&)
#60 GUIView::ProcessInputEvent(InputEvent&)
#61 -[GUIRenderView handleEvent:]
#62 -[GUIRenderView mouseDown:]
#63 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]
#64 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
#65 -[NSWindow(NSEventRouting) sendEvent:]
#66 -[NSApplication(NSEvent) sendEvent:]
#67 -[EditorApplicationPrincipalClass sendEvent:]
#68 -[EditorApplication TickTimer]
#69 __NSFireTimer
#70 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#71 __CFRunLoopDoTimer
#72 __CFRunLoopDoTimers
#73 __CFRunLoopRun
#74 CFRunLoopRunSpecific
#75 RunCurrentEventLoopInMode
#76 ReceiveNextEventCommon
#77 _BlockUntilNextEventMatchingListInModeWithFilter
#78 _DPSNextEvent
#79 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
#80 -[NSApplication run]
#81 NSApplicationMain
#82 EditorMain(int, char const**)
#83 main
#84 ???
Start bisecting. Delete HALF the code, patch over the bleeding. Same error? Restore that code, delete the other half.
Lather rinse repeat until you find the problem code. Bisecting works FAST, as powers of 2 are extremely … powerful.
Obviously I’m assuming you’re using source control properly so restoring code is one click.
Good idea. Thanks Kurt.
figure it out?
Try to build with Managed Code Stripping disabled. You have to switch to Windows Mono scripting backend for that. If it succeed it can be related to this Unity bug:
It was fixed in 2023.1.0a23, but not for other versions yet:
IL2CPP: Fixed scenarios where assemblies that were excluded from player builds could be pulled in during managed code stripping. (UUM-14403)
In this case vote for the fix.