Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidOperationException: No properties in class, has linker stripped it? #3363

Closed
89trillion-zhixin opened this issue Jun 26, 2023 · 11 comments · Fixed by #3373
Closed

InvalidOperationException: No properties in class, has linker stripped it? #3363

89trillion-zhixin opened this issue Jun 26, 2023 · 11 comments · Fixed by #3373

Comments

@89trillion-zhixin
Copy link

89trillion-zhixin commented Jun 26, 2023

What happened?

I'm having problems using Realm, Realm cannot create LocalResData, LocalResData is in the assembly, and Realm Init is in other assembly.

Unity: 2020.3.38f1
Relam: 11.1.2
Build:IL2CPP, Android

I don't know how to solve this problem, can anyone help me?

Repro steps

After I build Android apk, this issue will definitely happen

Version

4.x

What Atlas Services are you using?

Local Database only

What type of application is this?

Unity

Client OS and version

Unity 2020.3.38f1

Code snippets

This is LocalResData

using Realms;

namespace Functions.Core.Realms.RealmModel
{
    [Preserve(AllMembers = true)]
    public class LocalResData : RealmObject
    {
        [PrimaryKey, Preserve(AllMembers = true)] public int JoinId { get; set; }
        [Preserve(AllMembers = true)] public long Num { get; set; }

        public static void Init()
        {
        }
    }
}

This is init

public static void New(string userId)
{
    RealmConfiguration config = new RealmConfiguration($"{Application.persistentDataPath}/{userId}_JPG");
    config.Schema = new Type[]
    {
        typeof(LocalResData),
        typeof(TopicData)
    };
    config.EncryptionKey = Convert.FromBase64String(Url);
    config.SchemaVersion = 0;
    Realm = Realm.GetInstance(config);
}

I already have link.xml

<linker>
    <assembly fullname="Functions.Core" preserve="all"/>
</linker>

Stacktrace of the exception/crash you're getting

This is the error log

2023-06-27 00:20:41.927 22720-22873/? E/Unity: System.InvalidOperationException: No properties in LocalResData, has linker stripped it? See https://docs.mongodb.com/realm/sdk/dotnet/troubleshooting/#resolve-a--no-properties-in-class--exception
      at Realms.Schema.ObjectSchema+Builder..ctor (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
      at Realms.Schema.ObjectSchema+<>c.<FromType>b__23_0 (System.Type t) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00000] in <00000000000000000000000000000000>:0 
      at Realms.Schema.RealmSchema+Builder.Add (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
      at Realms.Schema.RealmSchema+Builder..ctor (System.Collections.Generic.IEnumerable`1[T] types) [0x00000] in <00000000000000000000000000000000>:0 
      at Realms.Schema.RealmSchema.op_Implicit (System.


### Relevant log output

_No response_
@nirinchev
Copy link
Member

Hey, do you have a minimal repro project you could share with us? That'll help quite a lot to pinpoint where the issue stems from.

@nirinchev nirinchev self-assigned this Jun 27, 2023
@avolkangursel
Copy link

Hello, we are also experiencing the same issue, and it is critical for us. Currently, we cannot release an update to our game due to this error. Unfortunately, I cannot share the project, but I can provide more details about the issue we are facing.

We didn't have this issue before. We simply updated the Realm SDK, and this problem started occurring. We started experiencing this problem after updating the Realm SDK from version 11.0.0 to version 11.1.2.

Unity: 2021.3.26f1
Realm: 11.1.2
Build: IL2CPP, Android, iOS

Important Note: We use CI/CD for publishing updates. While we don't encounter any issues when building locally, we face this problem when building from another device using "batch mode."

Both when building and when selecting "Weave Assemblies" from the "Tools" menu, we receive an error.

Could not analyze the user's assembly.
Cannot access a closed Stream.
#0 GetStacktrace(int)
#1 DebugStringToFile(DebugStringToFileData const&)
#2 DebugLogHandler_CUSTOM_Internal_Log(LogType, LogOption, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)
#3 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
#4 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
#5 (Mono JIT Code) [Logger.cs:60] UnityEngine.Logger:Log (UnityEngine.LogType,object)
#6 (Mono JIT Code) [Debug.bindings.cs:130] UnityEngine.Debug:LogError (object)
#7 (Mono JIT Code) RealmWeaver.UnityWeaver/UnityLogger:Error (string,Mono.Cecil.Cil.SequencePoint)
#8 (Mono JIT Code) RealmWeaver.Analytics:AnalyzeUserAssembly (Mono.Cecil.ModuleDefinition)
#9 (Mono JIT Code) RealmWeaver.Analytics/<>c__DisplayClass9_0:<.ctor>b__2 ()
#10 (Mono JIT Code) System.Threading.Tasks.Task:InnerInvoke ()
#11 (Mono JIT Code) System.Threading.Tasks.Task:Execute ()
#12 (Mono JIT Code) System.Threading.Tasks.Task:ExecutionContextCallback (object)
#13 (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
#14 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
#15 (Mono JIT Code) System.Threading.Tasks.Task:ExecuteWithThreadLocal (System.Threading.Tasks.Task&)
#16 (Mono JIT Code) System.Threading.Tasks.Task:ExecuteEntry (bool)
#17 (Mono JIT Code) System.Threading.Tasks.Task:System.Threading.IThreadPoolWorkItem.ExecuteWorkItem ()
#18 (Mono JIT Code) System.Threading.ThreadPoolWorkQueue:Dispatch ()
#19 (Mono JIT Code) System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
#20 (Mono JIT Code) (wrapper runtime-invoke) :runtime_invoke_bool (object,intptr,intptr,intptr)
#21 mono_jit_runtime_invoke
#22 do_runtime_invoke
#23 worker_callback
#24 worker_thread
#25 start_wrapper_internal
#26 start_wrapper
#27 GC_inner_start_routine
#28 GC_start_routine
#29 _pthread_start
#30 thread_start

Approximately 15 seconds after encountering this error, we also receive the following log:

Weaving completed. 0 assemblies needed weaving.
#0 GetStacktrace(int)
#1 DebugStringToFile(DebugStringToFileData const&)
#2 DebugLogHandler_CUSTOM_Internal_Log(LogType, LogOption, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)
#3 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
#4 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
#5 (Mono JIT Code) [Logger.cs:60] UnityEngine.Logger:Log (UnityEngine.LogType,object)
#6 (Mono JIT Code) [Debug.bindings.cs:102] UnityEngine.Debug:Log (object)
#7 (Mono JIT Code) RealmWeaver.UnityWeaver/UnityLogger:Info (string)
#8 (Mono JIT Code) RealmWeaver.UnityWeaver/d__20:MoveNext ()
#9 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:InvokeMoveNext (object)
#10 (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
#11 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
#12 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
#13 (Mono JIT Code) System.Threading.Tasks.AwaitTaskContinuation:InvokeAction (object)
#14 (Mono JIT Code) System.Threading.Tasks.AwaitTaskContinuation:RunCallback (System.Threading.ContextCallback,object,System.Threading.Tasks.Task&)
#15 (Mono JIT Code) System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run (System.Threading.Tasks.Task,bool)
#16 (Mono JIT Code) System.Threading.Tasks.Task:FinishContinuations ()
#17 (Mono JIT Code) System.Threading.Tasks.Task:FinishStageThree ()
#18 (Mono JIT Code) System.Threading.Tasks.Task1<int>:TrySetResult (int) #19 (Mono JIT Code) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetResult (int)
#20 (Mono JIT Code) RealmWeaver.UnityWeaver/d__24:MoveNext ()
#21 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:InvokeMoveNext (object)
#22 (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
#23 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
#24 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
#25 (Mono JIT Code) System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation/<>c:<.cctor>b__7_0 (object)
#26 (Mono JIT Code) [UnitySynchronizationContext.cs:153] UnityEngine.UnitySynchronizationContext/WorkRequest:Invoke ()
#27 (Mono JIT Code) [UnitySynchronizationContext.cs:83] UnityEngine.UnitySynchronizationContext:Exec ()
#28 (Mono JIT Code) [UnitySynchronizationContext.cs:107] UnityEngine.UnitySynchronizationContext:ExecuteTasks ()
#29 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
#30 mono_jit_runtime_invoke
#31 do_runtime_invoke
#32 mono_runtime_invoke
#33 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
#34 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
#35 Scripting::UnityEngine::UnitySynchronizationContextProxy::ExecuteTasks(ScriptingExceptionPtr*)
#36 Application::TickTimer()
#37 -[EditorApplication TickTimer]
#38 __NSFireTimer
#39 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
#40 __CFRunLoopDoTimer
#41 __CFRunLoopDoTimers
#42 __CFRunLoopRun
#43 CFRunLoopRunSpecific
#44 RunCurrentEventLoopInMode
#45 ReceiveNextEventCommon
#46 _BlockUntilNextEventMatchingListInModeWithFilter
#47 _DPSNextEvent
#48 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
#49 -[NSApplication run]
#50 NSApplicationMain
#51 EditorMain(int, char const**)
#52 main
#53 start

When we delete the "Library" folder from the project directory and open the project, we receive the following message normally.

Details

Weaving completed in 1412 ms.
1 class was woven:
RealmPref
ID: String [PrimaryKey]
OwnerID: String
PrefDictionary: IDictionary`2<System.String,System.String>

UnityEngine.Debug:Log (object)
RealmWeaver.UnityWeaver/UnityLogger:Info (string)
RealmWeaver.UnityWeaver:WeaveAssemblyCore (string,System.Collections.Generic.IEnumerable`1,string,string)
RealmWeaver.UnityWeaver/<>c__DisplayClass20_0:b__0 ()
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

I hope these details provide more clarity. If you need any further information, we can provide it.

@nirinchev
Copy link
Member

This looks similar to #3364. Can you try if the package linked in the last comment alleviates the issues for you?

@avolkangursel
Copy link

This looks similar to #3364. Can you try if the package linked in the last comment alleviates the issues for you?

Hello, I tried the package. The "Could not analyze the user's assembly." error seems to be resolved, but unfortunately, we still receive the "InvalidOperationException: No properties in class, has linker stripped it?" error when building with "batch mode" on the CI/CD machine.

@nirinchev
Copy link
Member

Can you share the logs when building on CI?

@avolkangursel
Copy link

Unfortunately, for privacy reasons, I cannot share the entire log of the project. Instead, I will try to reproduce the issue with a test project. If I can reproduce it, I can directly share the project.

Additionally, I can examine the log file on the CI machine and share the information I found. For example, when the API Updater runs, I see the following messages related to Realm:

[API Updater] Assemblies not requiring updates:

[API Updater] Packages/{package name}/Runtime/ThirdParty/Realm/Editor/Realm.UnityWeaver.dll (stdout below):
[AssemblyUpdater] Removing 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'Realm.UnityWeaver' list of referenced assemblies (no type referencing this assembly was found).
[API Updater] Packages/{package name}/Runtime/ThirdParty/Realm/Runtime/Realm.UnityUtils.dll (stdout below):

By the way, we are using the Realm SDK by including it in a custom package that we have created internally. Therefore, the file paths for the Realm DLLs are located within the Packages folder.

After the Tundra build, the error message below appeared precisely 94 times. It starts with the message
*** Tundra build success (18.56 seconds), 961 items updated, 1062 evaluated.

Then, in succession, the following error message occurs 94 times.

NullReferenceException: Object reference not set to an instance of an object
at RealmWeaver.UnityWeaver.GetAnalyticsConfig (System.Nullable`1[T] target) [0x0009b] in :0
at RealmWeaver.UnityWeaver+<>c.b__18_1 (System.String assemblyPath, UnityEditor.Compilation.CompilerMessage[] _) [0x0003e] in :0
at UnityEditor.Compilation.CompilationPipeline+<>c.b__23_2 (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly scriptAssembly, UnityEditor.Compilation.CompilerMessage[] messages) [0x0002a] in /Users/bokken/build/output/unity/unity/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:282
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEditor.Compilation.<>c:b__23_2(ScriptAssembly, CompilerMessage[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:286)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation:InvokeAssemblyCompilationFinished(ScriptAssembly[], BeeDriverResult, CompilerMessage[][]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1123)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation:ProcessCompilationResult(ScriptAssembly[], BeeDriverResult, Object) (at /Users/bokken/build/output/unity/unity/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1088)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget, Int32, String[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1052)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget, Int32, String[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:211)
UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[], Boolean)
UnityEditor.BuildPipeline:BuildPlayerInternal(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/BuildPipeline.bindings.cs:455)
UnityEditor.BuildPipeline:BuildPlayer(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/BuildPipeline.bindings.cs:348)
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions) (at /Users/bokken/build/output/unity/unity/Editor/Mono/BuildPipeline.bindings.cs:322)
Magiclab.MarketingSDK.Core.Editor.Build.BuilderCli:iOSBuild(String[], String, BuildTarget, BuildOptions) (at Library/PackageCache/com.magiclab.marketingsdk.core@d8d96022dc/Editor/Core/Build/BuilderCli.cs:118)
Magiclab.MarketingSDK.Core.Editor.Build.BuilderCli:BuildIOS() (at Library/PackageCache/com.magiclab.marketingsdk.core@d8d96022dc/Editor/Core/Build/BuilderCli.cs:34)

Apart from those, no other sentences are starting with "Weaving completed" or any other messages related to Realm.

@nirinchev
Copy link
Member

Thanks, that's quite helpful. I think I know what's going on - I've created a PR with a proposed fix and will give you a package to try as soon as CI builds it.

@avolkangursel
Copy link

Thank you very much. I can try it when the package arrives.

@nirinchev
Copy link
Member

Can you try this package and see if that still causes the error on CI?

@avolkangursel
Copy link

I apologize for the delayed response. I tried the package, and it seems that the issues have been resolved. Thank you very much.

@nirinchev
Copy link
Member

Thanks for confirming! We'll schedule an official release with the bugfix shortly.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants