Skip to content

Commit

Permalink
[MTGOSDK/Core/Remoting] RemoteHandle: Skip unresolved remote assembly…
Browse files Browse the repository at this point in the history
… references

Fixes issue where dynamic assemblies such as SharedHarmonyState would prevent future clients from connecting when dumping remote types.
  • Loading branch information
Qonfused committed Jan 22, 2025
1 parent 9d1a81a commit a292617
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private string MakeTypesResponse(HttpListenerRequest req)
if (matchingAssembly == null)
return QuickError($"No assemblies found matching the query '{assembly}'");

List<TypesDump.TypeIdentifiers> types = new List<TypesDump.TypeIdentifiers>();
List<TypesDump.TypeIdentifiers> types = new();
foreach (Type type in matchingAssembly.GetTypes())
{
types.Add(new TypesDump.TypeIdentifiers() { TypeName = type.FullName });
Expand Down
14 changes: 13 additions & 1 deletion MTGOSDK/src/Core/Remoting/RemoteHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.IO;

using MTGOSDK.Core.Logging;
using MTGOSDK.Core.Reflection;
using MTGOSDK.Core.Remoting.Interop;
using MTGOSDK.Core.Remoting.Interop.Interactions.Dumps;
Expand Down Expand Up @@ -127,7 +128,15 @@ internal RemoteHandle(Process procWithDiver, DiverCommunicator communicator)
_currentDomain = communicator.DumpDomain();
foreach (string assembly in _currentDomain.Modules)
{
_remoteTypes.Add(assembly, communicator.DumpTypes(assembly));
try
{
_remoteTypes.Add(assembly, communicator.DumpTypes(assembly));
}
catch (Exception e)
{
Log.Error("Failed to dump types for assembly '{Assembly}': {Message}",
assembly, e.Message);
}
}
_remoteObjects = new RemoteObjectsCollection(this);
Activator = new RemoteActivator(communicator, this);
Expand Down Expand Up @@ -191,6 +200,9 @@ public IEnumerable<CandidateType> QueryTypes(string typeFullName)
{
foreach (string assembly in _currentDomain.Modules)
{
if (!_remoteTypes.ContainsKey(assembly))
continue;

foreach (TypesDump.TypeIdentifiers type in _remoteTypes[assembly].Types)
{
if (type.TypeName == typeFullName)
Expand Down

0 comments on commit a292617

Please sign in to comment.