consumerbuilder< ignore,string>(conf).build()以统一方式工作,但部署到hololens时出现“sequence contains no matching element”错误

4nkexdtk  于 2021-06-04  发布在  Kafka
关注(0)|答案(0)|浏览(341)

下面的c#代码在unity编辑器中工作得很好-它设置了kafka,消息按预期记录。

using System;
using System.Linq;
using System.Threading;
using UnityEngine;
using Confluent.Kafka;

public class main : MonoBehaviour
{
    ConsumerBuilder<Ignore, string> cb;
    IConsumer<Ignore, string> c;
    ConsumerConfig conf;
    CancellationTokenSource cts;

    int milliseconds = 10;
    TimeSpan timeout;

    void Start()
    {
        print("main start");
        conf = new ConsumerConfig();
        conf.GroupId = "test-consumer-group";
        conf.BootstrapServers = "localhost:9092";
        conf.AutoOffsetReset = AutoOffsetReset.Earliest;

        cb = new ConsumerBuilder<Ignore, string>(conf);
        if (cb != null)
        {
            print("cb is ok: " + cb.ToString());
            c = cb.Build();
        }

        timeout = new TimeSpan(0, 0, 0, 0, milliseconds);
        c.Subscribe("testTopicName");
        cts = new CancellationTokenSource();

        print("main started");
    }

但是,当我构建visual studio解决方案并部署到hololens时,它抛出了一个异常:

Exception thrown at 0x776F3072 in MRB100.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x01F0BB84.
Exception thrown at 0x776F3072 in MRB100.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x01F0E384.
Exception thrown at 0x776F3072 in MRB100.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x01F0E384.
InvalidOperationException: Sequence contains no matching element
  at System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00000] in <00000000000000000000000000000000>:0 
  at Confluent.Kafka.Impl.Librdkafka.SetDelegates (System.Type nativeMethodsClass) [0x00000] in <00000000000000000000000000000000>:0 
  at Confluent.Kafka.Impl.Librdkafka.Initialize (System.String userSpecifiedPath) [0x00000] in <00000000000000000000000000000000>:0 
  at Confluent.Kafka.Consumer`2[TKey,TValue]..ctor (Confluent.Kafka.ConsumerBuilder`2[TKey,TValue] builder) [0x00000] in <00000000000000000000000000000000>:0 
  at Confluent.Kafka.ConsumerBuilder`2[TKey,TValue].Build () [0x00000] in <00000000000000000000000000000000>:0 
  at main.Start () [0x00000] in <00000000000000000000000000000000>:0 

(Filename: currently not available on il2cpp Line: -1)

如果我切断了线路 c = cb.Build(); (和 c.Subscribe("testTopicName"); ),错误消失。
我对c#/unity/hololens的开发还不熟悉,不知道该怎么做。我找到了几个答案http://taswar.zeytinsoft.com/linq-sequence-contains-no-matching-element/

For example if you use
> var result = myEnumerableCollection.First(x => x.Name == person.Name);

This will throw InvalidOperationException with Sequence contains no matching element.
But if you use
> var result = myEnumerableCollection.FirstOrDefault(x => x.Name == person.Name);
> if(result == null) //did not find in the collection something went wrong or .....

Which will return you a null if its not found then you can check if the result is null and continue on with your work

但是,据我所知,这种情况不适用于我的代码。
我上传了团结计划https://github.com/bitterdone/mrb100/tree/master
以及部署到hololens上的vs Build项目(1.2GB)https://github.com/bitterdone/mrb100/tree/000-addbuiltproject
任何想法或帮助都将不胜感激!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题