Mathijs-Bakker / Extenject

Dependency Injection Framework for Unity Game Engine
MIT License
509 stars 96 forks source link

Reflection baking doesn't work for assembly definitions #11

Open SolidAlloy opened 3 years ago

SolidAlloy commented 3 years ago

Describe the bug When a DLL of an assembly definition is added to assemblies included in Reflection Baking, the DLL gets broken and is not executed.

To Reproduce Steps to reproduce the behavior:

  1. Import Zenject into an empty project.
  2. Go to Assets/Plugins/Zenject/OptionalExtras/SampleGame1 (Beginner)/Scripts
  3. Create an assembly definition called Beginner and add Zenject to assembly definition references.
  4. Create the ZenjectReflectionBakingSettings scriptable object.
  5. Untick "All Generated Assemblies", tick "Is Enabled In Editor".
  6. Add Zenject.dll and Beginner.dll to included assemblies.
  7. Open the Asteroids scene.
  8. Enter Play Mode.
  9. Get the following errors:

Error when modifying type 'Asteroid'

FileNotFoundException: Could not load file or assembly 'Zenject-usage, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Unloading broken assembly Library/ScriptAssemblies/Beginner.dll, this assembly can cause crashes in the runtime

Detailed stack traces:

Error when modifying type 'Asteroid'
UnityEngine.Debug:LogError (object)
ModestTree.Log:ErrorException (string,System.Exception)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor:TryEditType (Zenject.ReflectionBaking.Mono.Cecil.TypeDefinition,System.Type) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:158)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor:Run () (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:84)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor:WeaveAssembly (Zenject.ReflectionBaking.Mono.Cecil.ModuleDefinition,System.Reflection.Assembly,System.Collections.Generic.List`1<string>) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:56)
Zenject.ReflectionBaking.ReflectionBakingBuildObserver:TryWeaveAssembly (string) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Unity/ReflectionBakingBuildObserver.cs:93)
Zenject.ReflectionBaking.ReflectionBakingBuildObserver:OnAssemblyCompiled (string,UnityEditor.Compilation.CompilerMessage[]) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Unity/ReflectionBakingBuildObserver.cs:37)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,string[])
FileNotFoundException: Could not load file or assembly 'Zenject-usage, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) (at <695d1cc93cca45069c528c15c9fdd749>:0)
Zenject.Internal.ReflectionTypeAnalyzer+<>c__DisplayClass12_1.<GetMethodInfos>b__1 (System.Type a) (at <e711547f4dd74929ab297f402fe81f63>:0)
System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
Zenject.Internal.ReflectionTypeAnalyzer+<>c.<GetMethodInfos>b__12_0 (System.Reflection.MethodInfo x) (at <e711547f4dd74929ab297f402fe81f63>:0)
System.Linq.Enumerable+WhereArrayIterator`1[TSource].ToList () (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
Zenject.Internal.ReflectionTypeAnalyzer.GetMethodInfos (System.Type type) (at <e711547f4dd74929ab297f402fe81f63>:0)
Zenject.Internal.ReflectionTypeAnalyzer.GetReflectionInfo (System.Type type) (at <e711547f4dd74929ab297f402fe81f63>:0)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor.TryEditType (Zenject.ReflectionBaking.Mono.Cecil.TypeDefinition typeDef, System.Type actualType) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:144)
UnityEngine.Debug:LogException(Exception)
ModestTree.Log:ErrorException(String, Exception)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor:TryEditType(TypeDefinition, Type) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:158)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor:Run() (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:84)
Zenject.ReflectionBaking.ReflectionBakingModuleEditor:WeaveAssembly(ModuleDefinition, Assembly, List`1) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Common/ReflectionBakingModuleEditor.cs:56)
Zenject.ReflectionBaking.ReflectionBakingBuildObserver:TryWeaveAssembly(String) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Unity/ReflectionBakingBuildObserver.cs:93)
Zenject.ReflectionBaking.ReflectionBakingBuildObserver:OnAssemblyCompiled(String, CompilerMessage[]) (at Assets/Plugins/Zenject/OptionalExtras/ReflectionBaking/Unity/ReflectionBakingBuildObserver.cs:37)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget, String[])

Expected behavior Reflection is baked for Beginner.dll, the are no broken DLLs.

Screenshots image image

Extenject and Unity info (please complete the following information):

Bezarius commented 2 years ago

It seems to me that this feature should be removed, because reflection is baked through il2cpp. I fixed this problem in my project and the a bench showed that the project even slowed down a little.