Skip to content

.net 10.0 issue with Channeltype does not inherit from channel #97

@gerbaten

Description

@gerbaten

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;

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions