DotNetty:IllegalReferenceCountException

时间:2018-03-25 22:49:59

标签: c# .net azure

我试图实施DotNetty但有一个奇怪的问题?

错误讯息:

  

DotNetty.Buffers.IllegalReferenceCountException:'此对象的非法引用计数为0'

错误图片:https://i.imgur.com/oGMxDgt.png

它在哪里发生?

class RankingForm(forms.ModelForm):
    rank = forms.IntegerField(max_value=3, min_value=1)
    position = forms.ModelMultipleChoiceField(queryset=Positions.objects.none())

    class Meta:
        model = Ranking
        exclude = ['applicant']
        fields = ['rank', 'position']

    def __init__(self, *args, **kwargs):
        super(RankingForm, self).__init__(*args, **kwargs)
        self.fields['rank'].widget.attrs.update({'class': 'form-control'})  
        self.fields['position'].queryset = self.instance.positions.all()

这是完整的课程。

public bool HasLength => Buffer.GetInt(0) > -1;

这是调用public class ServerPacket { public IByteBuffer Buffer { get; } public short Id { get; private set; } public ServerPacket(short id) { Buffer = Unpooled.Buffer(); Id = id; Buffer.WriteInt(-1); Buffer.WriteShort(id); } public bool HasLength => Buffer.GetInt(0) > -1; public void WriteByte(int b) => Buffer.WriteByte((byte)b); public void WriteDouble(double d) => WriteString(d.ToString()); public void WriteString(string s) // d { Buffer.WriteShort(s.Length); Buffer.WriteBytes(Encoding.Default.GetBytes(s)); } public void WriteShort(int s) => Buffer.WriteShort(s); public void WriteInteger(int i) => Buffer.WriteInt(i); public void WriteBoolean(bool b) => Buffer.WriteByte(b ? 1 : 0); } 方法的类。

HasLength

如何发送ServerPacket实例?

public class Encoder : MessageToMessageEncoder<ServerPacket>
{
    protected override void Encode(IChannelHandlerContext context, ServerPacket message, List<Object> output)
    {
        if (!message.HasLength)
        {
            message.Buffer.SetInt(0, message.Buffer.WriterIndex - 4);
        }

        output.Add(message.Buffer);
    }
}

发送ServerPacket实例时会发生此错误,此处为代码。

public void SendPacket(ServerPacket packet)
{
    _context.WriteAndFlushAsync(packet);
}

0 个答案:

没有答案