Azure / Azure/DotNetty

TypeInitializationException: The type initializer for 'TailContext' threw an exception

Open
#500 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.3k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I use DotNetty in Unity2018, and encounter the following exception
```
Exception
ArgumentNullException: Value cannot be null.
Parameter name: element
System.Attribute.GetCustomAttributes (System.Reflection.MemberInfo element, System.Type type, System.Boolean inherit) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.Attribute.GetCustomAttribute (System.Reflection.MemberInfo element, System.Type attributeType, System.Boolean inherit) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.Reflection.CustomAttributeExtensions.GetCustomAttribute (System.Reflection.MemberInfo element, System.Type attributeType, System.Boolean inherit) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T] (System.Reflection.MemberInfo element, System.Boolean inherit) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
DotNetty.Transport.Channels.AbstractChannelHandlerContext.IsSkippable (System.Type handlerType, System.String methodName, System.Type[] paramTypes) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.AbstractChannelHandlerContext.CalculateSkipPropagationFlags (System.Type handlerType) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.DefaultChannelPipeline+TailContext..cctor () (at <22a0a3c55c4140ceadffadf96839be25>:0)
Rethrow as TypeInitializationException: The type initializer for 'TailContext' threw an exception.
DotNetty.Transport.Channels.DefaultChannelPipeline..ctor (DotNetty.Transport.Channels.IChannel channel) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.AbstractChannel.NewChannelPipeline () (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.AbstractChannel..ctor (DotNetty.Transport.Channels.IChannel parent) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.Sockets.AbstractSocketChannel..ctor (DotNetty.Transport.Channels.IChannel parent, System.Net.Sockets.Socket socket) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.Sockets.AbstractSocketByteChannel..ctor (DotNetty.Transport.Channels.IChannel parent, System.Net.Sockets.Socket socket) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.Sockets.TcpSocketChannel..ctor (DotNetty.Transport.Channels.IChannel parent, System.Net.Sockets.Socket socket, System.Boolean connected) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.Sockets.TcpSocketChannel..ctor (DotNetty.Transport.Channels.IChannel parent, System.Net.Sockets.Socket socket) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.Sockets.TcpSocketChannel..ctor (System.Net.Sockets.Socket socket) (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Channels.Sockets.TcpSocketChannel..ctor () (at <22a0a3c55c4140ceadffadf96839be25>:0)
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <982b38b882344e069fa104c0b0b4ebb3>:0)
System.Activator.CreateInstance[T] () (at <982b38b882344e069fa104c0b0b4ebb3>:0)
DotNetty.Transport.Bootstrapping.AbstractBootstrap`2+<>c__10`1[TBootstrap,TChannel,T].b__10_0 () (at <22a0a3c55c4140ceadffadf96839be25>:0)
DotNetty.Transport.Bootstrapping.AbstractBootstrap`2+d__27[TBootstrap,TChannel].MoveNext () (at <22a0a3c55c4140ceadffadf96839be25>:0)
```
I located the exception at `DotNetty.Transport.Channels.AbstractChannelHandlerContext` and fix it
```
protected static bool IsSkippable(Type handlerType, string methodName, params Type[] paramTypes)
{
var newParamTypes = new Type[paramTypes.Length + 1];
newParamTypes[0] = typeof(IChannelHandlerContext);
Array.Copy(paramTypes, 0, newParamTypes, 1, paramTypes.Length);
// may be null
// return handlerType.GetMethod(methodName, newParamTypes).GetCustomAttribute(false) != null;
// replace
return handlerType.GetMethod(methodName, newParamTypes)?.GetCustomAttribute(false) != null;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.