praeclarum / praeclarum/sqlite-net
IL2CPP does not support inspection of attribute constructor arguments at run time.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
I am using sqlite-net for a Unity project. My current settings include relying on IL2CPP compiler instead of Mono when building the binary. This is something I cannot change. Apparently IL2CPP has a problem with ConstructorArguments (for iOS/Android builds, not in Unity Editor):
NotSupportedException: ./External/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection/CustomAttributeData.cpp(17) : Unsupported internal call for IL2CPP:CustomAttributeData::ResolveArgumentsInternal - "IL2CPP does not support inspection of attribute constructor arguments at run time."
at System.Reflection.CustomAttributeData.ResolveArguments () [0x00000] in <00000000000000000000000000000000>:0
at System.Reflection.CustomAttributeData.get_ConstructorArguments () [0x00000] in <00000000000000000000000000000000>:0
at SQLite.Orm.InflateAttribute (System.Reflection.CustomAttributeData x) [0x00000] in <00000000000000000000000000000000>:0
at SQLite.TableMapping+<>c.<.ctor>b__31_1 (System.Reflection.CustomAttributeData x) [0x00000] in <00000000000000000000000000000000>:0
at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0
at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00000] in <00000000000000000000000000000000>:0
at SQLite.TableMapping..ctor (System.Type type, SQLite.CreateFlags createFlags) [0x00000] in <00000000000000000000000000000000>:0
at SQLite.SQLiteConnection.GetMapping (System.Type type, SQLite.CreateFlags createFlags) [0x00000] in <00000000000000000000000000000000>:0
The problem is anywhere ConstructorArguments property is used.
For now, I have fixed this problem by adding a #define and using different code (older code taken from this repo, not really sure which version tbh) whenever ConstructorArguments is used. e.g.:
#if UNITY_EDITOR
var typeInfo = type.GetTypeInfo();
var tableAttr =
typeInfo.CustomAttributes
.Where(x => x.AttributeType == typeof(TableAttribute))
.Select(x => (TableAttribute)Orm.InflateAttribute(x))
.FirstOrDefault();
#elif NETFX_CORE
var tableAttr = (TableAttribute)System.Reflection.CustomAttributeExtensions
.GetCustomAttribute(type.GetTypeInfo(), typeof(TableAttribute), true);
#else
var tableAttr = (TableAttribute)type.GetCustomAttributes(typeof(TableAttribute), true).FirstOrDefault();
#endif
or
#if UNITY_EDITOR
Name = (colAttr != null && colAttr.ConstructorArguments.Count > 0) ?
colAttr.ConstructorArguments[0].Value?.ToString() :
prop.Name;
#else
Name = colAttr == null ? prop.Name : colAttr.Name;
#endif
Maybe there's a better way to fix this problem than that, but I wanted to know if this issue could be addressed officially?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SQLite.TableMapping constructor and SQLite.Orm.InflateAttribute calls shown in the stack trace, then review each use of CustomAttributeData. Compare the existing UNITY_EDITOR, NETFX_CORE, and fallback paths in the issue. Done means attribute mapping no longer accesses ConstructorArguments in IL2CPP iOS or Android builds while preserving the reported table and column behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100