-
Notifications
You must be signed in to change notification settings - Fork 38
Description
i am using named pipes i moved to .net10.0 and now i get after a few calls System.ArgumentException: channelType does not inherit from Channel at ServiceWire.NamedPipes.NpClient1..ctor(NpEndPoint npAddress, ISerializer serializer, ICompressor compressor, ILog logger, IStats stats
according to github co pilot the solution might be to cache createdtype.
calling Type t = proxyBuilder.TypeBuilder.CreateTypeInfo(); multiple times might caused the error for .net10.0
suggested changes by copilot
`
internal sealed class ProxyBuilder
{
public string ProxyName { get; set; }
public Type InterfaceType { get; set; }
public Type CtorType { get; set; }
public AssemblyBuilder AssemblyBuilder { get; set; }
public ModuleBuilder ModuleBuilder { get; set; }
public TypeBuilder TypeBuilder { get; set; }
// Cache the created type to avoid calling CreateTypeInfo() multiple times
private Type _createdType;
private readonly object _lockObject = new object();
public Type GetOrCreateType()
{
if (_createdType == null)
{
lock (_lockObject)
{
if (_createdType == null)
{
_createdType = TypeBuilder.CreateTypeInfo();
}
}
}
return _createdType;
}
}
`
`
private static TInterface CreateProxy(ProxyBuilder proxyBuilder, object channelCtorValue, ISerializer serializer, ICompressor compressor, ILog logger, IStats stats) where TInterface : class
{
//create the type and construct an instance
Type[] ctorArgTypes = new Type[] { typeof(Type), proxyBuilder.CtorType, typeof(ISerializer), typeof(ICompressor), typeof(ILog), typeof(IStats) };
// Use the cached type instead of calling CreateTypeInfo() repeatedly
Type t = proxyBuilder.GetOrCreateType();
var constructorInfo = t.GetConstructor(ctorArgTypes);
if (constructorInfo != null)
{
TInterface instance = (TInterface)constructorInfo.Invoke(new object[] { typeof(TInterface), channelCtorValue, serializer, compressor, logger, stats });
return instance;
}
return null;
}
`