Getting errors from BuildPipeline.BuildAssetBundles but not when building game...

I have looked at a number of threads about errors between editor and production builds related to AssetBundles:

https://answers.unity.com/questions/316805/unityeditor-namespace-not-found.html?_ga=2.189548139.1946127219.1585938144-183802302.1574265257
https://forum.unity.com/threads/scripts-in-editor-folders-throwing-build-errors-when-building-assetbundles-for-mobile.482755/
They do not seem to relate to the issue I am having. I can do in editor builds of the game for Android, iOS, and WebGL and they run in the editor.

But, when I call the BuildPipeline.BuildAssetBundles API the Photon 3rd party library gives a bunch of errors like this one:

Yet the code looks very straight forward:

using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public class ChatEditor : EditorWindow

It is the class declaration is line 21 that is showing the error.

It seems like maybe there is some compiler defines set that are different when the BuildPipeline.BuildAssetBundles is called as compared to what is set during editor builds?

Any ideas? It is a major stumbling block for me right now.

There is an update to the Photon Library that I am going to pull in next but I don’t have a lot of confidence that will fix it. The current code that is showing the error looks pretty good.

@Krellumdaed

It’s a crappy solution, but you need to wrap any classes giving you that error in

#if UNITY_EDITOR
using Foo;

public class Bar
{
    // code here
}
#endif

I’m not entirely sure why, but the BuildAssetBundles() function wants to build stuff inside Editor folders as if they’re supposed to run in the game.