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
System.PlatformNotSupportedException: Operation is not supported on this platform. #67
Comments
Thank you for this very important report! This issue is known but unfortunately not really documented anywhere, as the primary goal in BepInEx 4.x is to support pre-Unity 2017 games. Pre-emptive TL; DR (or a TL; WR, I suppose): New Unity games built against .NET Standard have API Harmony relies on disabled. There is a fix coming in BepInEx 5.0. Note: if you notice any mistakes or typos, feel free to correct me! Unity and the panoply of scripting backendsWhile Unity is known for using .NET as its scripting backend, different Unity games may use a different common language runtimes (that runs the code) and different API profiles (what .NET API is included with the game). Currently, Unity supports the following CLRs (Unity Documentation):
In addition to that, each backend provides different .NET API (i.e. standard libraries that are used to write code). In Unity those are usually called the .NET profiles (or the combination of scripting runtime and API compatibility level). There are quite a few variations depending on the version of Unity, but here are the most interesting ones (Unity Documentation):
Note different versions of Unity have different availability for these API. While in older versions of Unity only the first two are available, the newer versions (2018.1 and up) have the ability to switch between the first and the last two APIs (via the scripting runtime option) (MSDN). Now that we covered the what, here's the why (if you're only interested in the reasoning for this issue, skip to the next section. BepInEx and scripting backendsThe main goal of BepInEx is to provide support for games using Mono as the CLR. This is simply because supporting the other two runtimes is not practical or possible:
As a result, BepInEx only works on Unity games with Mono backend. If Unity decides to move to coreclr in the future, BepInEx might be updated to accommodate that. BepInEx and .NET APIsIt is important to understand that .NET Standard 2.0 and .NET 4.x are not the same in contents. Most importantly, .NET Standard 2.0 does not have API for dynamically generate code in memory (Unity Forums, Unity Forums). Since .NET Standard 2.0 became an option in newer versions of Unity, some games built with 2018.1 will simply not have the API Harmony needs to work. And since preloader relies on Harmony, preloader will crash. TL; DR: How to fix?Wait until BepInEx 5.0 is out (or build For devs: how to patch methods in .NET Standard gamesAs it is unlikely that Harmony will ever update to address this issue (since that would require a massive library overhaul), here's a list of alternatives for method hooking:
If you are aware of any other alternatives, do let me know. I'll close the issue when the fix is merged to master and when I manage to port this reply to BepInEx docs. |
I don't know if that the right place to update this issue here or create a new one but it's related to that same issue so I'll comment here 😄 So basically, I installed the BepInEx 5.0RC from the Thing is I still have the
It appears to happen even without any plugins inside the |
Greetings! Thanks for bringing this back up! This issue does indeed now have a fix in 5.0, but currently it is not fully finalised in RC1. However, there is a workaround for it: To make BepInEx work on .NET Standard games, open [Preloader]
ApplyRuntimePatches = false Setting Note that in .NET Standard games Harmony is unavailable to use (for now), if you need to do runtime patching, BepInEx now included MonoMod's RuntimeDetour library that allows to do that. Finally, I must reiterate that this is still an issue that is being worked on. In full release this workaround may not be necessary. |
Ok so I think to have found a good workaround since I really want to use Harmony and I thought it would be interesting for anyone wanting to use BepInEx and Harmony! TL;DR: pardeike/Harmony#172 (comment) In the latest .NET Framework versions starting 4.6, some namespaces seem to have been stripped down from the exported libraries of the built Unity game (especially Basically, someone tried to drop the I haven't try patching something yet (so no deep testing from my side) but it looks like Harmony now load correctly and BepInEx plugins are perfectly loaded since the exception disappeared. |
This workaround is known and is apparently used by some mod loaders. While it might be very tempting to just replace DLLs that are core to CLR runtime itself, I do not recommend it. If it was recommended and fine, this workaround would've been posted here a long time ago. As I mentioned in my original comment on this issue, Unity games that ship with .NET Standard 2.0 API instead of .NET 4.x have some of their API stripped. It all seems nice and easy, but there are some major caveats. Why it is not recommended to swap
|
Thank you for your reply! To be fair, I'm still bit new into injections and patching and only know a few things from Harmony 😄 I didn't think swapping that .dll would be this bad haha I guess for now I'll stick with Thanks again for your complete reply, that helped me understand the actual issue of it and how it works internally better! |
for linux: you'll get this error when running with the builtin winhttp |
Thanks to significant work done by Horse and 0x0ade, in BepInEx 5.0, Harmony can now be used in games that use the .NET Standard runtime by piggybacking off of MonoMod.RuntimeDetour. I'll be closing this issue, but if the issue reappears, please reopen it. |
Describe the bug
I think preloader doesn't work because in new version of Unity is using .NET(v4.0.30319)
To Reproduce
Just start the game
Expected behavior
To use plugin with new version of game.
Screenshots and logs
Desktop (please complete the following information):
PEiD of Assembly-CSharp.dll
PEiD of BepInEx.dll
The text was updated successfully, but these errors were encountered: