diff --git a/VContainer/Assets/VContainer/Runtime/Internal/ReflectionInjector.cs b/VContainer/Assets/VContainer/Runtime/Internal/ReflectionInjector.cs index 62f5db26..8b1847da 100644 --- a/VContainer/Assets/VContainer/Runtime/Internal/ReflectionInjector.cs +++ b/VContainer/Assets/VContainer/Runtime/Internal/ReflectionInjector.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Reflection; namespace VContainer.Internal { @@ -31,6 +30,12 @@ public void Inject(object instance, IObjectResolver resolver, IReadOnlyList parameters) { +#if UNITY_2020_1_OR_NEWER + if (typeof(UnityEngine.Component).IsAssignableFrom(injectTypeInfo.Type)) + { + throw new NotSupportedException($"UnityEngine.Component:{injectTypeInfo.Type.Name} cannot be `new`"); + } +#endif var parameterInfos = injectTypeInfo.InjectConstructor.ParameterInfos; var parameterKeys = injectTypeInfo.InjectConstructor.ParameterKeys; var parameterValues = CappedArrayPool.Shared8Limit.Rent(parameterInfos.Length);