Error while creating WP8 build

Hi,

I getting below error when im trying to make a build for WP8 platform.

Error building Player: Exception: Failed to run assembly preprocessor with command line “Temp/StagingArea/Data/Managed\Assembly-CSharp.dll” -injectCtor -assemblyPath “Temp/StagingArea” -pdb.[Temp/StagingArea/Data/Managed\Assembly-CSharp.dll]
Symbols will be read from Temp/StagingArea/Data/Managed\Assembly-CSharp.dll.mdb
Injecting ctor
Injecting fast invokes
Error while in assembly preprocessor Temp/StagingArea/Data/Managed\Assembly-CSharp.dll

/////////////

For all other platforms its working fine.
So can you guys let me know what seems to be going wrong.

Thanks

Hi,

I’ve been having a similar problem and was able to debug into it using ProcMon.exe (a free Windows tool) and .NET Reflector Pro (not so free but ABSOLUTELY worth its money).

With ProcMon I managed to find the actual command line tool with the Parameters it is called with. On my system, the call was

“C:\Program Files (x86)\Unity4\Editor\Data\PlaybackEngines\wp8support\Tools\AssemblyPreprocessor.exe” “C:\projectname\Temp/StagingArea/Data/Managed\Assembly-CSharp.dll” -injectCtor -assemblyPath “C:\projectname\Temp/StagingArea” -pdb

With .NET Reflector I was able to decompile the tool and debug into it quite easily (as I said, .NET Reflector rocks).
In my case, the problem turned out to be caused by an abstract Start() method in a MonoBehaviour. AssemblyPreprocessor.exe can’t handle that and crashes.

Maybe this helps you resolve your problem as well (it should!).

Hey Seraph, these methods are not available in the Editor. Be sure to wrap the respective calls with proper defines. This code snipped from our code base should give you a start. You’ll still need to import System.Reflection, as you’ve figured out already.

#if !UNITY_EDITOR && UNITY_WINRT
        public static bool IsValueType(Type type)
        {
            return type.GetTypeInfo().IsValueType;
        }

        private static IEnumerable<Type> GetBaseTypes(Type type)
        {
            yield return type;

            var baseType = type.GetTypeInfo().BaseType;

            if (baseType != null)
            {
                foreach (var t in GetBaseTypes(baseType))
                {
                    yield return t;
                }
            }
        }

        public static PropertyInfo GetProperty(Type type, string name)
        {
            return
                GetBaseTypes(type)
                    .Select(baseType => baseType.GetTypeInfo().GetDeclaredProperty(name))
                    .FirstOrDefault(property => property != null);
        }

        public static MethodInfo GetMethod(Type type, string name)
        {
            return
                GetBaseTypes(type)
                    .Select(baseType => baseType.GetTypeInfo().GetDeclaredMethod(name))
                    .FirstOrDefault(method => method != null);
        }

        public static FieldInfo GetField(Type type, string name)
        {
            return
                GetBaseTypes(type)
                    .Select(baseType => baseType.GetTypeInfo().GetDeclaredField(name))
                    .FirstOrDefault(field => field != null);
        }

        public static bool IsEnum(Type type)
        {
            return type.GetTypeInfo().IsEnum;
        }

        public static Delegate CreateDelegate(Type type, object target, MethodInfo method)
        {
            return method.CreateDelegate(type, target);
        }

        public static bool IsAssignableFrom(Type first, Type second)
        {
            return first.GetTypeInfo().IsAssignableFrom(second.GetTypeInfo());
        }
#else
        public static bool IsValueType(Type type)
        {
            return type.IsValueType;
        }

        public static PropertyInfo GetProperty(Type type, string name)
        {
            return type.GetProperty(name);
        }

        public static MethodInfo GetMethod(Type type, string name)
        {
            return type.GetMethod(name);
        }

        public static bool IsEnum(Type type)
        {
            return type.IsEnum;
        }

        public static FieldInfo GetField(Type type, string name)
        {
            return type.GetField(name);
        }

        public static Delegate CreateDelegate(Type type, object target, MethodInfo method)
        {
            return Delegate.CreateDelegate(type, target, method);
        }

        public static bool IsAssignableFrom(Type first, Type second)
        {
            return first.IsAssignableFrom(second);
        }
#endif

I also get the same error. In addition, another error is also comes with it.

Type System.Type' does not contain a definition for GetTypeInfo’ and no extension method GetTypeInfo' of type System.Type’ could be found (are you missing a using directive or an assembly reference?)

but I already added using System.Reflection and I checked this method is supported by Windows Store App and WP8.

Did any other guy have similar problem?

Thanks

Just make sure that no project is open in Visual Studio while you are building it.
Closing visual studio worked for me.

As npruehs says, wrap the code with #IF !UNITY_EDITOR && UNITY_WINRT, and also make sure you have using System.Reflection;

GetTypeInfo is an extension method in the System.Reflection namespace.