[Unity3D daily BUG record] during Unity packaging operation: PlatformNotSupportedException the platform does not support the solution record of this operation

Recommended reading

Hello, I'm a Buddhist Engineer ☆ quiet little magic dragon ☆. I update Unity development skills from time to time. I think it's useful. Remember to click three times.

1, Foreword

Today, we encountered a problem PlatformNotSupportedException. The platform does not support this operation. Please record the solution.

First, describe the problem. The code runs normally in the Unity editor. The code has been studied many times and there is no problem.

Finally, there is no way. Choose package to start Debug debugging:

Then an error occurs:

PlatformNotSupportedException: Operation is not supported on this platform. 
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod (System. String name, System. Type returnType, System. Type[] parameterTypes, System. Type owner) [0x00018] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory. CreateDefaultConstructor[T] (System. Type type) [0x00010] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System. Type createdType) [0x00005] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization. JsonContract contract) [0x00093] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System. Type objectType) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System. Type objectType) [0x0010f] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]. GetOrAdd (TKey key, System. Func`2[T,TResult] valueFactory) [0x00034] in <c79628fadf574d3a8feae0871fad28ef>:0 
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[TKey,TValue]. Get (TKey key) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System. Type type) [0x0000b] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContract (System. Object value) [0x00011] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System. Object value) [0x00005] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json. JsonWriter jsonWriter, System. Object value, System. Type objectType) [0x00028] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json. JsonWriter jsonWriter, System. Object value, System. Type objectType) [0x0023a] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json. JsonWriter jsonWriter, System. Object value, System. Type objectType) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System. Object value, System. Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00028] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonConvert.SerializeObject (System. Object value, System. Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonConvert.SerializeObject (System. Object value) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at MainControl. ReturnJson () [0x00087] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:85 
at MainControl. CurrentStepSave () [0x00028] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:60 
at PageChange. ChangePage (System. Int32 index1, System. Int32 index2, System. String step, ExpStepSwitch step2) [0x00018] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:241 
at MainControl. CurrentStepParse () [0x00267] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:147 
at LoginControl. LoginReceive (System. String value) [0x0010f] in E:\Working\PantsDesign_HDR\Assets\Scripts\1_Login\LoginControl.cs:240 
at WebRequestControl+<>c__DisplayClass1_0. <RequestDataFormat>b__0 (System. String value) [0x00001] in E:\Working\PantsDesign_HDR\Assets\Scripts\Web\WebRequestControl.cs:23 
at WebRequestControl+<RequestData>d__2. MoveNext () [0x000cf] in E:\Working\PantsDesign_HDR\Assets\Scripts\Web\WebRequestControl.cs:47 
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections. IEnumerator enumerator, System. IntPtr returnValueAddress) [0x00026] in <11823353802e452f95fbecfc4daf365f>:0 

2, Analysis

According to the error message: PlatformNotSupportedException: Operation is not supported on this platform

Then find the keyword newtonsoft Json. Serialization, I used newtonsoft JSON serialization tool.

Then, after commenting out the relevant code, there are no more errors, so the rest is to solve this part of the code.

2, Solution

First, baidu found an article:

Platformnotsupportedexception in Unity package exe (connecting to MySQL): operation is not supported on this platform Question of

This article is due to the PlatformNotSupportedException: Operation is not supported on this platform using MySQl. It is different from our mistakes. Try it with a try attitude:

Find the Api Compatibility Level under Project Settings and change it to NET 4.x:

Wait for the editor to compile without errors, and directly package and generate.

There are no errors, the program is normal, and the problem is solved.

4, Summary

This is a good problem to solve, but this kind of problem often puzzles Xiaobai for a day or even longer.

However, I hope interested people can learn something from this article.

For example, what to do when encountering a BUG, how to find problems and how to solve problems, let's finally sort out the following:

  • (1) Problems encountered
  • (2) Check whether the code is correct and whether it runs normally in the editor
  • (3) there is a problem after packaging, using the following debugging tools: UnityDebugViewer, KGFDebug, UnityIngameDebugConsole
  • (4) Find the problem code, comment and check whether the program runs completely.
  • (5) If there is still a problem after the comment, repeat the above operation to lock the problem code segment
  • (6) If you can solve the code problem, you can solve the code problem. If you can't solve it, Baidu will see if there is the same problem. After all, others you meet may also encounter it. The pit you step on is the one that others have filled.
  • (7) Solve problems, organize ideas, record problems or BUG solutions, so that people behind don't step on the pit.

Keywords: Unity 3d

Added by nano on Thu, 13 Jan 2022 05:05:15 +0200