I’ve been using this service for a while now without issue, but now I’ve started getting a Cloud Build error that says that I’m using a method that doesn’t exist (System.IO.File.WriteAllBytes() doesn’t exist when building for web-player), but it is wrapped in a #if UNITY_EDITOR block, so I don’t understand why it’s getting compiled. Is there a compile-error check that takes place before the preprocessor is used to trim code?
Did you add this part or was it always there? Did you add anything which could alter the file, for example a post process script which removes a #endif by accident?
I did add the if block recently (in my last checkin), but I don’t have any post-process code in the project at all. The project compiles just fine locally when I build it in editor or for iOS.
Could you attach the log of the project or post the snippet you use? I assume it’s a file in the Editor folder?
Well, it’s not in an Editor folder, because it’s a runtime class. Editor classes don’t have much use for an #if UNITY_EDITOR directive.
Here is a code snippet:
public void GenerateMap() {
// ... This is where I generate the map image...
#ifUNITY_EDITOR
if (!Application.isPlaying && mapTexture) {
string path = AssetDatabase.GetAssetPath(mapTexture);
if (string.IsNullOrEmpty(path)) {
path = AssetUtil.GenerateUniqueAssetPathAtSelection("QuestMapTexture.png");
}
byte[] bytes = mapTexture.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
}
#endif
}
And here is the build log:
[Unity] Initialize engine version: 5.0.1f1 (5a2e8fe35a68)
3: [Unity] -----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll
4: [Unity] Compilation failed: 1 error(s), 0 warnings
5: [Unity] Assets/Unearth/Scripts/Quests/QuestDefinition.cs(200,40): error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
6: [Unity] /UNITY_PATH/Unity/Unity-5_0_1/Unity.app/Contents/Frameworks/Mono/lib/mono/unity_web/mscorlib.dll (Location of the symbol related to previous error)
7: [Unity] Assets/Unearth/Scripts/Quests/QuestDefinition.cs(200,40): error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
8: [Unity] Scripts have compiler errors.
9: [Unity] Scripts have compiler errors.
10: [Unity] Initialize engine version: 5.0.1f1 (5a2e8fe35a68)
11: [Unity] -----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll
12: [Unity] Compilation failed: 1 error(s), 0 warnings
13: [Unity] Assets/Unearth/Scripts/Quests/QuestDefinition.cs(200,40): error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
14: [Unity] /UNITY_PATH/Unity/Unity-5_0_1/Unity.app/Contents/Frameworks/Mono/lib/mono/unity_web/mscorlib.dll (Location of the symbol related to previous error)
15: [Unity] Assets/Unearth/Scripts/Quests/QuestDefinition.cs(200,40): error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
16: [Unity] Scripts have compiler errors.
17: [Unity] Scripts have compiler errors.
18: ! build of 'default-web' failed. compile failed
19: Finished: FAILURE
Status: FAILED
Yes, sorry that makes no sense if you have it in the Editor folder. I just wanted to test you
#ifUNITY_EDITOR
Not sure if it’s just copy and past error, but #if UNITY_EDITOR needs to have space in between #if and UNITY_EDITOR. Can you confirm there is a space?
Right, there should be a space there. I thought I fixed all the copy errors. My project does compile just fine. I’m not sure why this forum has such trouble with pasted code.
It should not if you use the code blocks input. Anyway, I’m not sure if this solved the issue or if it’s still not building in UCB?
I made no changes to my project (the space was there in my original code), so it’s still not building in UCB.
My project may be corrupted somehow. I also see this first ‘could not be found’ error when I remove/rename any files in my project (notice that the original error is still there at the bottom):
[Unity] Initialize engine version: 5.0.1f1 (5a2e8fe35a68)
[Unity] -----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll
[Unity] Compilation failed: 1 error(s), 0 warnings
[Unity] error CS2001: Source file `Assets/Unearth/Scripts/Procedural/Algorithms/Voronoi.cs' could not be found
[Unity] error CS2001: Source file `Assets/Unearth/Scripts/Procedural/Algorithms/Voronoi.cs' could not be found
[Unity] -----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll
[Unity] Compilation failed: 1 error(s), 0 warnings
[Unity] Assets/Unearth/Scripts/Quests/QuestDefinition.cs(239,40): error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
[Unity] /UNITY_PATH/Unity/Unity-5_0_1/Unity.app/Contents/Frameworks/Mono/lib/mono/unity_web/mscorlib.dll (Location of the symbol related to previous error)
[Unity] Assets/Unearth/Scripts/Quests/QuestDefinition.cs(239,40): error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
[Unity] Scripts have compiler errors.
[Unity] Scripts have compiler errors.
[Unity] Initialize engine version: 5.0.1f1 (5a2e8fe35a68)
The first error goes away if I commit again.
Is there any way (without getting an Enterprise account) to get in touch with someone within UCB who can take a look at my project in their system, to see if something has been borked? Perhaps my project just needs to be reset somehow.
If you use Clean Build All, does the first error disappear?
You can make a new app at any time and try it as a fresh one.
What’s the name of the project in UCB?
I believe that any new build will fix the first error. I have tried Clean Build All several times, but it has no affect on the second error. Our project is called, “Unearth”.
Could you please try and change it to and try it again?
#if UNITY_EDITOR && !UNITY_CLOUD_BUILD
Hi David,
Well that did stop that error from showing up, although it seems to be a bit of a hack.
I still get errors when I delete/rename files (but they may be innocuous, since the build still succeeds and produces an installable).
Summary: 1 warnings, 8 errors:
[Unity] Initialize engine version: 5.0.1f1 (5a2e8fe35a68)
[Unity] -----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp-firstpass.dll
[Unity] Compilation failed: 3 error(s), 0 warnings
[Unity] error CS2001: Source file `Assets/Plugins/Voronoi/Demos/Editor/VoronoiDemoEditor.cs' could not be found
[Unity] error CS2001: Source file `Assets/Plugins/Voronoi/Demos/FractureChunk.cs' could not be found
[Unity] error CS2001: Source file `Assets/Plugins/Voronoi/Demos/VoronoiDemo.cs' could not be found
[Unity] error CS2001: Source file `Assets/Plugins/Voronoi/Demos/Editor/VoronoiDemoEditor.cs' could not be found
[Unity] error CS2001: Source file `Assets/Plugins/Voronoi/Demos/FractureChunk.cs' could not be found
[Unity] error CS2001: Source file `Assets/Plugins/Voronoi/Demos/VoronoiDemo.cs' could not be found
Also, now that I’ve updated to the latest Unity (5.0.1f1), when I try to run the successfully built game in the web player, it keeps telling me I need to install the Unity Web Player. I’ve tried that several times now even closing Chrome down during the process, but it still doesn’t seem to think I have it installed anymore. This is a separate issue, I’m sure, but rather disappointing.
Hi @glennpow - this is probably due to the new version of Chrome disabling NPAPI support. If you test it in other browsers it should work …for more information see here:
@hypeNate - ah, I see. I will use other browsers for the time being. Thanks.
In the meantime, should I file a bug for the main issue of this thread? The additional conditional does remove the error, but it seems odd that other files work just fine with only the UNITY_EDITOR check.
So Cloud Build IS the Unity Editor - therefore that block will always be executed, unless you modify it to skip it using the syntax David provided.
I’m not sure what is causing the errors when that code is run, however. Is that the bug you were describing?
Wait… the Cloud Build system is the Unity Editor when it builds for a platform? That doesn’t seem right.
When it builds for a platform (iOS, Web, etc.) it should be building as that platform. I know you guys work for Unity and everything, but I’m pretty sure that’s how it has to work. Otherwise all the other #if UNITY_EDITOR checks in all the other files in my project would be compiling broken platform-specific builds.
Plus if it were the Unity Editor then it wouldn’t be throwing that error because System.IO.File.WriteAllBytes() would exist.
Anyway, there are 2 Cloud Build issues that have been discussed in this thread:
- The fact that code inside an #if UNITY_EDITOR block is throwing a compile error, when it should be getting stripped.
- If I remove/rename any files, I see a ‘Source file … could not be found’ compiler error the first time I commit/build. That error doesn’t seem to stop a build from being successfully created though (even though it says ‘compilation failed’)
For issue #2 - try a clean build, it might resolve any inconsistencies …let us know how it goes!
Once again, any further builds (whether clean or not) will definitely remove the file-not-found errors, so I’m not (as) worried about them.
Issue #1 is still my main concern. It definitely seems like a bug in the UCB compilation system, and I’d worry it could have unforeseen consequences.
If nobody else is seeing this problem, it very well may be that my project has been corrupted in UCB (all platforms build fine on my machine), but I would very much prefer NOT to delete my current project just to recreate a new one. Is there any way that someone within Unity can simply wipe out my project’s repo (and any other metadata), but leave the build logs et al?