Modding:Modder Guide/Test and Troubleshoot

From Stardew Valley Wiki
Jump to navigation Jump to search

Creating SMAPI mods SMAPI mascot.png


Modding:Index

This page helps solve common issues when creating mods. For issues using mods, see Modding:Player Guide/Troubleshooting.

Fix common build warnings

After building your project, you can see build warnings via Visual Studio > View > Error List or MonoDevelop > View > Pads > Errors. Here are some common ones.

Mismatch between the processor architecture...

Sample warning: "There was a mismatch between the processor architecture of the project being built "{0}" and the processor architecture of the reference "{1}". This mismatch may cause runtime failures."

That warning is normal. The error is saying that your build is set to 'Any CPU', but Stardew Valley is x86-only so it'll only work in x86 anyway. You can either ignore it, or change your platform target to x86.

This implicitly converts...

Sample warning: "This implicitly converts '{0}' from Net{1} to {2}, but Net{1} has unintuitive implicit conversion rules. Consider comparing against the actual value instead to avoid bugs. See https://smapi.io/buildmsg/avoid-implicit-net-field-cast for details."

Your code is referencing a net field, which can cause subtle bugs. This field has an equivalent non-net property, like monster.Health (int) instead of monster.health (NetBool). Change your code to use the suggested property instead.

FieldName is a Net* field...

Sample warning: "'{0}' is a Net{1} field; consider using the {2} property instead. See https://smapi.io/buildmsg/avoid-net-field for details."

Your code is referencing a net field, which can cause subtle bugs. You should access the underlying value instead:

  • For a reference type (i.e. one that can contain null), you can use the .Value property (or .FieldDict for a NetDictionary):
    if (building.indoors.Value == null)
    

    Or convert the value before comparison:

    GameLocation indoors = building.indoors.Value;
    if(indoors == null)
       // ...
    
  • For a value type (i.e. one that can't contain null), check if the parent is null (if needed) and compare with .Value:
    if (item != null && item.category.Value == 0)
    

The FieldName field is obsolete...

Sample warning: "The 'Character.friendships' field is obsolete and should be replaced with 'friendshipData'. See https://smapi.io/buildmsg/avoid-obsolete-field for details."

You're referencing a field which should no longer be used. Use the suggested field name instead to fix it.

An instance of analyzer ... cannot be created

Update to the latest Visual Studio 2017; the NuGet package uses a recent feature that isn't available in older versions.

Other issues

Can't target .NET Framework 4.5

If the target framework list has options starting with...

  • ".NET Core" or ".NET Standard": you created the wrong type of project. Make sure you create a .NET Framework project for your mod. (It's a bit confusing.)
  • ".NET Framework" (but none for 4.5): you can use .NET Framework 4.5, 4.5.1, or 4.5.2. If you don't have any of those, you can install the .NET Framework 4.5.2 Developer Pack to add it.

Ask for help

If you still need help, ask for help in #modding on the Stardew Valley Discord. The Stardew Valley modding community is very welcoming!