- Home /
Mono Error when compiling scripts
Hey guys, I am getting a strange error when attempting to compile my project. This project used to compile just fine until I was trying to merge some assets using the Import/Export package functionality and a few of my resources were replaced (no prompt for replacing assets btw...). I managed to recover all the scripts that were replaced and I have the project compiling into a dll just fine in VS2008 Express but when I attempt to re-import the scripts in Unity I get the following error:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at Mono.CSharp.Argument.Emit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Invocation.EmitArguments (Mono.CSharp.EmitContext ec, System.Reflection.MethodBase mb, System.Collections.ArrayList arguments, Boolean dup_args, Mono.CSharp.LocalTemporary this_arg) [0x00000] at Mono.CSharp.Invocation.EmitCall (Mono.CSharp.EmitContext ec, Boolean is_base, Mono.CSharp.Expression instance_expr, System.Reflection.MethodBase method, System.Collections.ArrayList Arguments, Location loc, Boolean dup_args, Boolean omit_args) [0x00000] at Mono.CSharp.PropertyExpr.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load) [0x00000] at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) [0x00000] at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Conditional.Emit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Argument.Emit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Invocation.EmitArguments (Mono.CSharp.EmitContext ec, System.Reflection.MethodBase mb, System.Collections.ArrayList arguments, Boolean dup_args, Mono.CSharp.LocalTemporary this_arg) [0x00000] at Mono.CSharp.Invocation.EmitCall (Mono.CSharp.EmitContext ec, Boolean is_base, Mono.CSharp.Expression instance_expr, System.Reflection.MethodBase method, System.Collections.ArrayList Arguments, Location loc, Boolean dup_args, Boolean omit_args) [0x00000] at Mono.CSharp.PropertyExpr.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load) [0x00000] at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) [0x00000] at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] at Mono.CSharp.Switch.TableSwitchEmit (Mono.CSharp.EmitContext ec, System.Reflection.Emit.LocalBuilder val) [0x00000] at Mono.CSharp.Switch.DoEmit (Mono.CSharp.EmitContext ec) [0x00000]
I also noticed this section in the Editor.log
Couldn't load the script "Game" because its file name doesn't match the class name. Please make sure the file name of the script is the same as the class defined inside it. (Filename: /Users/build/builds/unity-iphone-1.5/iphone-1.1/Projects/../Runtime/Mono/MonoScript.cpp Line: 410)
I went and double checked the Game.cs script file and and it has a class named "Game" which inherits from the MonoBehaviour class. It has this same error for every other script in the project as well.
Answer by Shawn · Jan 21, 2010 at 06:40 PM
Had a typo in an inline condition which caused the above crash.
SettingsManager.MusicVolume = (SettingsManager.MusicVolume > 0) ? SettingsManager.MusicVolume = 0 : SettingsManager.MusicVolume = 0.5f;
should have been
SettingsManager.MusicVolume = (SettingsManager.MusicVolume > 0) ? 0 : 0.5f;
Must have been day dreaming while writing that :). Strange that it would kill the compiler though. It does not even cause an error or warning inside of VS2008. Must be a bug in the older version of Mono.
If you still have the script that makes mono's compiler crash, we'd love to get it (Unitymenu->help->report a problem), so we can make sure that the problem is really gone when we put in a new mono.
Your answer
Follow this Question
Related Questions
BuildPipeline.BuildPlayer misnames .pbxuser file 3 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Get error on iPhone (Sealed Class) when trying to build iOS Game for Windows 1 Answer
How can I stop the variable values reverting to its default values after being built? 1 Answer
ExecutionEngineException: Attempting to JIT compile method 1 Answer