Skip to content

fix: Skip read-only properties in mock resolution#468

Merged
MSchmoecker merged 1 commit intoValheim-Modding:devfrom
jneb802:fix-skip-readonly-properties-in-mock-resolution
Mar 6, 2026
Merged

fix: Skip read-only properties in mock resolution#468
MSchmoecker merged 1 commit intoValheim-Modding:devfrom
jneb802:fix-skip-readonly-properties-in-mock-resolution

Conversation

@jneb802
Copy link
Copy Markdown
Contributor

@jneb802 jneb802 commented Feb 12, 2026

Summary

  • Adds HasSetMethod property to MemberBase to track whether a member has a setter
  • Guards SetValue calls in MockManager.FixMemberReferences with HasSetMethod check, preventing crashes on read-only properties like Component.transform

Problem

When mods trigger FixReferences on GameObjects with read-only component properties (e.g. Component.transform), MockManager.FixMemberReferences crashes with:

ArgumentException: Set Method not found for 'transform'
  at System.Reflection.RuntimePropertyInfo.SetValue(...)
  at Jotunn.PropertyMember.SetValue(...)
  at Jotunn.Managers.MockManager.FixMemberReferences(...)

The method iterates all properties via reflection and calls SetValue without checking if a setter exists.

Steps to reproduce

  1. Install Jotunn v2.27.1, ExpandWorldData, and More World Locations AIO
  2. Launch the game and load into a world
  3. During ZoneSystem.Start, EWD triggers SoftReference.Load() on MWL location prefabs
  4. Jotunn's AssetManager.SwapResolvedAsset hook fires, calling PrefabExtension.FixReferences on the loaded prefab
  5. MockManager.FixMemberReferences encounters read-only properties like Component.transform and crashes calling SetValue

Fix

Follows the existing HasGetMethod pattern — adds a symmetric HasSetMethod property and checks it before SetValue calls in the two branches that write values back.

Prevents ArgumentException when FixMemberReferences encounters read-only
properties like Component.transform by adding a HasSetMethod check before
calling SetValue.
@MSchmoecker MSchmoecker merged commit d64c122 into Valheim-Modding:dev Mar 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants