"IL2CPP error for method 'System.Collections.Generic.Dictionary`2<K,V> Babu.Core.StringConverter::ConvertToDict(System.String,System.Char,System.Char)' in assembly '/home/ab/jenkins/workspace/CangLong/Develop/BuildTestAndroid/Game.Client/Temp/StagingArea/assets/bin/Data/Managed/Babu.Core.dll'" System.NullReferenceException: Object reference not set to an instance of an object.' at Unity.IL2CPP.MethodBodyWriter.WriteMethodCallExpression(String returnVariable, Func`1 getHiddenMethodInfo, IGeneratedMethodCodeWriter writer, MethodReference callingMethod, MethodReference methodToCall, MethodReference unresolvedMethodtoCall, TypeResolver typeResolverForMethodToCall, MethodCallType callType, IRuntimeMetadataAccess runtimeMetadataAccess, IVTableBuilder vTableBuilder, IEnumerable`1 argumentArray, Boolean useArrayBoundsCheck, Func`2 addUniqueSuffix) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodBodyWriter.cs:line 2816' at Unity.IL2CPP.MethodBodyWriter.WriteCallExpressionFor(MethodReference callingMethod, MethodReference unresolvedMethodToCall, MethodCallType callType, List`1 argsFor, Func`2 addUniqueSuffix, Boolean emitNullCheckForInvocation) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodBodyWriter.cs:line 2730' at Unity.IL2CPP.MethodBodyWriter.WriteCallExpressionFor(MethodReference unresolvedMethodToCall, MethodCallType callType, List`1 poppedValues, Func`2 addUniqueSuffix, Boolean emitNullCheckForInvocation) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodBodyWriter.cs:line 2687' at Unity.IL2CPP.MethodBodyWriter.ProcessInstruction(Node node, InstructionBlock block, Instruction& ins) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodBodyWriter.cs:line 1021' at Unity.IL2CPP.MethodBodyWriter.GenerateCodeRecursive(Node node) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodBodyWriter.cs:line 359' at Unity.IL2CPP.MethodBodyWriter.Generate() in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodBodyWriter.cs:line 191' at Unity.IL2CPP.CodeWriters.CodeWriterExtensions.WriteMethodWithMetadataInitialization(IGeneratedMethodCodeWriter writer, String methodSignature, String methodFullName, Action`2 writeMethodBody, String uniqueIdentifier, MethodReference methodRef) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/CodeWriters/CodeWriterExtensions.cs:line 117' at Unity.IL2CPP.MethodWriter.WriteMethodDefinition(AssemblyWriteContext context, IGeneratedMethodCodeWriter writer, MethodReference method, Boolean addToMethodCollection) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/MethodWriter.cs:line 70' at Unity.IL2CPP.SourceWriter.WriteGenericMethodDefinition(SourceWritingContext context, IGeneratedMethodCodeWriter writer, GenericInstanceMethod method) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/SourceWriter.cs:line 67' at Unity.IL2CPP.SourceWriters.SourceWriterBase`1.WriteItem(StreamWorkItemData`2 data) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/SourceWriters/SourceWriterBase.cs:line 86' at Unity.IL2CPP.Contexts.Scheduling.Streams.FileLevelParallelStreamManager`2.WorkerWriteItemsToFile(WorkItemData`2 data) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/Contexts.Scheduling.Streams/FileLevelParallelStreamManager.cs:line 33' at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data) in /Users/bokken/build/output/fmwang/il2cpp/Unity.IL2CPP/Contexts.Scheduling/PhaseWorkScheduler.cs:line 317'
Unity 2020.3用的是.net 4.x/.net standard 2.0 相当于.net framework 4.6
而我VS编译选择的Target是.net standard 2.1,所以导致打包出错。将VS Target改成.net framework 4.6.2进行编译就可以了。
唯一的问题是VS不论是.netstandard 2.0还是.net framework 4.x都不支持C# 8.0导致一些写法要改下,比如var a ??= new A(),稍微麻烦点。(但是Unity的.net 4.x却又是可以支持C# 8.0的)
另外我看了下Unity 2021.3版本已经支持了.net standard 2.1了,但是另外一个选项虽然不叫.net 4.x,但是还是叫.net framework,看介绍是可以即支持.net standard 2.1同时也支持最新的.net framework。所以如果是Unity 2021.3以后的版本可以直接使用VS编译出来的.net standard 2.1版本的库了。