NetworkManagerEditor can cause reflection issues
Description
During the ReloadTransports method of NetworkManagerEditor.cs, it calls AppDomain.CurrentDomain.GetAssemblies(); in order to dynamically load all assemblies, and then search through every type in order to find subclasses of NetworkTransport. While this likely wont be an issue for the vast majority of projects, the product I'm currently developing references several native plugins and dlls (Specifically GRPC and Protobuf) that cause reflection errors when this is called.
Reproduce Steps
- Add some DLL that can cause reflection issues to the project, such as GRPC.Core.IAsyncStreamWriter
- Click on the NetworkManager
Actual Outcome
A ReflectionTypeLoadException is thrown
Expected Outcome
Nothing interesting happens
Screenshots
Environment
- OS: Windows 10
- Unity Version: 2022.3.2f1
- Netcode Version:1.4.0
Additional Context
Technically speaking, this is an issue with the GRPC dll and not the editor script. However it does feel a little odd to me that an editor script is iterating over every type in the project to find classes that are of type UnityTransport. I am definitely NOT an expect of domains, low level C#, or Editor Tools (Im a graphics engineer), but it does seem somewhat unusual to me, so Im raising the issue! I hope its helpful <3
(Nevermind this comment, I commented on the wrong issue.)
I'm unsure of how this would solve the problem? Could you elaborate a bit to help me out?
@Reag Sorry, I commented on the wrong issue, ignore me!
@Reag I haven't yet been able to replicate this issue. What I have done so far:
- Went to the nuget GRPC package
- Opened it with 7zip
- extracted the .NET 2.0 Grpc.Core.Api.dll into a test project
- created a script file
- referenced the Grpc.Core namespace
- put together a quick stream writer implementation using
IAsyncStreamWriter - created class property from that implementation class type.
- in the Start method instantiated and assigned the instance to the property
- tried this two different ways:
- As a
MonoBehaviourcomponent attached to theGameObjectwith aNetworkManagercomponent. - As a
NetworkBehaviourcomponent attached to an in-scene placedNetworkObject.
- As a
With the above steps, I could not get the same exception to occur. There could be something else unique to what you are doing that is causing the issue.
Could you provide a reproduction project?
@NoelStephensUnity
I believe this error stopped happening some time around 1.6 or so. I remember reading through the changes and noticing that the code that caused this reflection issue was fixed. I honestly thought that it was handled internally and this issue was closed!