RegisterDynamicTypeDef fall back

This commit is contained in:
2026-08-20 00:32:01 +03:00
parent 3e608ef1d1
commit f14dc633ae
6 changed files with 167 additions and 4 deletions
@@ -1393,7 +1393,11 @@ partial class EpConnection
{
var typeDefs = LocalTypeDef.GetDependencies(localTypeDef, Instance.Warehouse);
// Send
SendReply(EpPacketReply.Completed, callback, typeDefs.Select(x => x.Compose(this)).ToArray());
// Cast reference-type arrays to object so C# does not expand
// them into SendReply's params object[] argument. The array is
// one protocol value, not N reply arguments.
SendReply(EpPacketReply.Completed, callback,
(object)typeDefs.Select(x => x.Compose(this)).ToArray());
}
else
{
@@ -1582,7 +1586,10 @@ partial class EpConnection
var list = children
.Where(x => IsOperationAllowed(x, null, ActionType.Attach))
.ToArray();
SendReply(EpPacketReply.Completed, callback, list);
// IResource[] is covariant with object[]; without this
// cast a one-child Query becomes one bare resource on the
// wire instead of a ResourceList.
SendReply(EpPacketReply.Completed, callback, (object)list);
}).Error(e =>
{
SendError(e.Type, callback, (ushort)e.Code, e.Message);
@@ -3098,7 +3105,14 @@ partial class EpConnection
var defs = new List<RemoteTypeDef>();
foreach (var def in (byte[][])result)
var typeDefinitions = result switch
{
byte[][] values => values,
object[] values => values.Cast<byte[]>().ToArray(),
_ => throw new InvalidCastException($"Expected an array of type definitions, received {result?.GetType().FullName ?? "null"}.")
};
foreach (var def in typeDefinitions)
{
var od = new RemoteTypeDef();
await RemoteTypeDef.Parse(od, _remoteDomain, def, this, null);
@@ -3825,7 +3839,14 @@ partial class EpConnection
SendRequest(EpPacketRequest.Query, path)
.Then(result =>
{
reply.Trigger((IResource[])result);
var resources = result switch
{
IResource[] values => values,
object[] values => values.Cast<IResource>().ToArray(),
_ => throw new InvalidCastException($"Expected a resource array, received {result?.GetType().FullName ?? "null"}.")
};
reply.Trigger(resources);
}).Error(ex => reply.TriggerError(ex));
return reply;
+11
View File
@@ -1375,7 +1375,18 @@ public class Warehouse
}
if (_remoteTypeDefs[domain].ContainsKey(typeDef.Id))
{
// Remote definitions are scoped by domain and survive an
// EpConnection reconnect in the Warehouse cache. A freshly
// parsed definition for that same remote id must inherit the
// Warehouse-local id of the cached definition. Leaving it at
// zero makes Instance.RegisterDynamicTypeDef fall back to the
// producer's wire id, which can collide with an unrelated
// local CLR definition.
var existing = _remoteTypeDefs[domain][typeDef.Id];
typeDef.LocalTypeDefId = existing.LocalTypeDefId;
return false;
}
// @TODO: Try to find a proxy type for the remote type def, if not found, create a new proxy type and register it in the warehouse.
_remoteTypeDefs[domain][typeDef.Id] = typeDef;