Search Unity

Extension method must be defined in a non-generic static class

Discussion in 'Windows' started by castor76, Dec 10, 2016.

  1. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    I have long but pretty straight forward monobehaviour script that works fine in Unity, and on all other platforms but when I build for UWP 10, it gives this error :

    Extension method must be defined in a non-generic static class

    I have checked the class and it doesn't seem to have any extension methods or any other static methods at all...

    It's really puzzling on why only during build time it fails to compile.

    I am thinking it is because of difference in .net version but clueless on where to look to start solving this issue.

    has anyone had similar issue with buiding to UWP 10?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,188
    Could you paste the whole errors, including the script it's complaining about?
     
  3. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    I think I have found the issue for that one. But I am still seeing far too many issues with UWP porting process.

    Such as :

    Assets\Daikon Forge\DFGUI\Scripts\Internal\dfSupportClasses.cs(449,28): error CS0246: The type or namespace name 'TypeInfo' could not be found (are you missing a using directive or an assembly reference?)

    #if !UNITY_EDITOR && UNITY_WSA
    if( member is FieldInfo )
    return MemberTypes.Field;
    if( member is ConstructorInfo )
    return MemberTypes.Constructor;
    if( member is PropertyInfo )
    return MemberTypes.Property;
    if( member is EventInfo )
    return MemberTypes.Event;
    if( member is MethodInfo )
    return MemberTypes.Method;

    var typeInfo = member as TypeInfo;
    if( typeInfo.IsNested )
    return MemberTypes.NestedType;

    return MemberTypes.TypeInfo;
    #else
    return member.MemberType;
    #endif

    So I thought TypeInfo should and could be used for UWP 10? Using IL2CPP Win 10 UWP. This only happens upon build.
    Or is it TypeInfo only works against NetCore compile?

    How is it different from compiling against NetCore and IL2CPP ?
     
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    I also get these kind of errors :

    Assets/Game/Script/Unit/Common/UnitMovement.cs(62,36): error CS0012: The type `System.Collections.Generic.List`1<PathologicalGames.Target>' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Collections, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    And ofcourse the code and everything works on every other platforms including consoles.. But not on UWP..
    (Unity 5.5)
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,161
    You should use NETFX_CORE instead of UNITY_WSA for .NET differences. The same code is compiled for Editor where mono is used, so UNITY_WSA should be for platform specific code paths, but not .NET profile specific code.
     
  6. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    Is this the same case for IL2CPP? Does it make difference? In fact, when does IL2CPP differ from .Net compile when it comes to UWP 10 build? I realize this could be a bit broader question then what I started the thread with, but I am ultimately trying to understand it better..
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,161
    NETFX_CORE is defined when compiling using MS compiler and .NET subset for UWP (actually any WSA SDK).
    IL2CPP uses Mono compiler and relevant .NET profile, so this define will not be present. It will also not be there when script are compiled for running in the editor.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,188
    With IL2CPP you get exact same API of .NET 3.5 (the same as the editor and any other Unity platforms). The API is only different on .NET scripting backend, and that is because we don't get to choose it (on IL2CPP and other unity platforms we ship our own class libraries).

    NETFX_CORE is defined only when building for .NET scripting backend. That should be used for #ifdefing special paths such as "GetTypeInfo", as that one is present only on .NET scripting backend. IL2CPP path should use the same code as the editor.
     
  9. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    I see! Thanks for the explanation. In such case, I think my best chance is to go with IL2CPP. If I can only figure out why it is failing on link stage :

    Failed running C:\Program Files\Unity\Editor\Data\Tools/UnusedByteCodeStripper2/UnusedBytecodeStripper2.exe -out "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\tempStrip" -l none -c link -b True -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Core.xml" -f "C:\Program Files\Unity\Editor\Data\il2cpp\LinkerDescriptors" -x "D:\SubUWP\trunk/Temp\StagingArea\Data/methods_pointedto_by_uievents.xml" -x "D:\SubUWP\trunk\Temp\StagingArea\Data\preserved_derived_types.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\AI.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Animation.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Audio.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\CloudWebServices.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Core.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\IMGUI.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\JSONSerialize.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\ParticlesLegacy.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\ParticleSystem.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Physics.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Physics2D.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Terrain.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\TerrainPhysics.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\TextRendering.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UI.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UNET.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityAds.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityAnalytics.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityConnect.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityWebRequest.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\VR.xml" -x "C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Web.xml" -x "D:\SubUWP\trunk\Assets\AstarPathfindingProject\link.xml" -x "D:\SubUWP\trunk\Assets\JsonDotNet\link.xml" -d "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-CSharp-firstpass.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-UnityScript-firstpass.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-UnityScript.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\BehaviorDesignerRuntime.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\DOTween.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\PlayMaker.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\TileSystem.Runtime.dll" -a "D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\usequencerRuntime.dll"

    stdout:
    Fatal error in Mono CIL Linker
    Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Runtime.CompilerServices.ExtensionAttribute::.ctor()
    ��ġ: Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
    ��ġ: Mono.Linker.Steps.MarkStep.MarkCustomAttribute(CustomAttribute ca)
    ��ġ: Mono.Linker.Steps.MarkStep.MarkCustomAttributes(ICustomAttributeProvider provider)
    ��ġ: Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly)
    ��ġ: Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
    ��ġ: Mono.Linker.Steps.MarkStep.Initialize()
    ��ġ: Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    ��ġ: Mono.Linker.Pipeline.Process(LinkContext context)
    ��ġ: Mono.Linker.Driver.RunDriver(Driver driver)
    stderr:

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:94)
    UnityEditorInternal.AssemblyStripper:RunAssemblyLinker(IEnumerable`1, String&, String&, String, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:101)
    UnityEditorInternal.AssemblyStripper:StripAssembliesTo(String[], String[], String, String, String&, String&, String, IIl2CppPlatformProvider, IEnumerable`1, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:94)
    UnityEditorInternal.AssemblyStripper:RunAssemblyStripper(String, IEnumerable, String, String[], String[], String, IIl2CppPlatformProvider, RuntimeClassRegistry, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:198)
    UnityEditorInternal.AssemblyStripper:StripAssemblies(String, IIl2CppPlatformProvider, RuntimeClassRegistry, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:125)
    UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:201)
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:128)
    PostProcessUAPIl2Cpp:RunIL2CPP() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAPIl2Cpp.cs:92)
    PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:134)
    UnityEditor.HostView:OnGUI()

    1111111111111111111
     
  10. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    Tried on Unity 5.5 :

    Failed running C:\Program Files\Unity5.5\Editor\Data\il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --enable-symbol-loading --extra-types.file="C:\Program Files\Unity5.5\Editor\Data\il2cpp\il2cpp_default_extra_types.txt" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-CSharp-firstpass.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-UnityScript-firstpass.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\Assembly-UnityScript.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\DOTween.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\PlayMaker.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\UnityEngine.dll" --assembly="D:\SubUWP\trunk\Temp\StagingArea\Data\Managed\System.dll" --generatedcppdir="D:\SubUWP\trunk\Temp\StagingArea\Il2CppOutputProject\il2cppOutput"

    stdout:
    IL2CPP error (no further information about what managed code was being converted is available)
    Additional information: Build a development build for more information. Exception has been thrown by the target of an invocation.
    il2cpp.exe didn't catch exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Unable to resolve [UnityEngine]UnityEngine.BitStream.
    at Unity.IL2CPP.Common.WindowsRuntimeAwareMetadataResolver.Resolve(TypeReference type)
    at Mono.Cecil.TypeReference.Resolve()
    at Unity.IL2CPP.Extensions.IsInterface(TypeReference type)
    at Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Visit(Instruction instruction, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(MethodBody methodBody, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.Cecil.Visitor.Extensions.DoAccept[T](T definition, Visitor visitor)
    at Unity.IL2CPP.AssemblyConverter.PreProcessStage(InflatedCollectionCollector& genericsCollectionCollector, TypeDefinition[]& allTypeDefinitions)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(NPath[] assemblies, NPath outputDir, NPath dataFolder)
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder)
    at il2cpp.Program.DoRun(String[] args)
    at il2cpp.Program.Run(String[] args)
    at il2cpp.Program.Main(String[] args)
    stderr:

    Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Unable to resolve [UnityEngine]UnityEngine.BitStream.
    at Unity.IL2CPP.Common.WindowsRuntimeAwareMetadataResolver.Resolve(TypeReference type)
    at Mono.Cecil.TypeReference.Resolve()
    at Unity.IL2CPP.Extensions.IsInterface(TypeReference type)
    at Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Visit(Instruction instruction, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(MethodBody methodBody, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.Cecil.Visitor.Extensions.DoAccept[T](T definition, Visitor visitor)
    at Unity.IL2CPP.AssemblyConverter.PreProcessStage(InflatedCollectionCollector& genericsCollectionCollector, TypeDefinition[]& allTypeDefinitions)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(NPath[] assemblies, NPath outputDir, NPath dataFolder)
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder)
    at il2cpp.Program.DoRun(String[] args)
    at il2cpp.Program.Run(String[] args)
    at il2cpp.Program.Main(String[] args)

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:96)
    UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:281)
    UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(ICollection`1, String, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:272)
    UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:126)
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:32)
    PostProcessUAPIl2Cpp:RunIL2CPP() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAPIl2Cpp.cs:92)
    PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:135)
    UnityEditor.HostView:OnGUI()
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,188
    UnityEngine.BitStream is a class from legacy networking (aka RakNet). RakNet was never supported on Windows Store - the lack of support for it is not related to scripting backend. Perhaps you have a DLL in your project that references that type?

    Sorry about the error message being super unclear. We have this fixed in 5.6.
     
  12. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,389
    I see! Thanks for the info. Is there any way to find out which of dll is using the BitStream? I have done search on usual find in files for the terms and I could not find it. So it is got to be in dll. Any idea?
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,188
    You can use ILSpy to see what's inside DLL files.