markiodev / Networker

A simple to use TCP and UDP networking library for .NET. Compatible with Unity.
MIT License
477 stars 77 forks source link

Unable to resolve service for type 'Networker.Common.Abstractions.IPacketSerialiser' #18

Closed Akronae closed 5 years ago

Akronae commented 6 years ago

Hi, I'm trying to play with Networker, so I just installed this package, then I set a simple server like this

    public sealed class UdpServer
    {
        private readonly IServer _server;

        public UdpServer (int port)
        {
            _server = new ServerBuilder().UseUdp(port).RegisterPacketHandlerModule<PacketHandler>().Build();
        }

        public void Start ()
        {
            _server.Start();
            Console.WriteLine($"UdpServer running on ${_server}");
        }
    }

And as soon as I instanciate UdpServer (not even calling Start) i got this error:

> Unhandled Exception: System.InvalidOperationException: Unable to resolve service for type 'Networker.Common.Abstractions.IPacketSerialiser' while attempting to activate 'Networker.Server.ServerPacketProcessor'. > at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) > at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet`1 callSiteChain) > at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet`1 callSiteChain) > at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet`1 callSiteChain) > at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) > at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet`1 callSiteChain) > at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet`1 callSiteChain) > at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet`1 callSiteChain) > at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) > at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary`2 dictionary, TKey key, Func`3 valueFactory, TArg arg) > at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) > at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) > at Networker.Server.ServerBuilder.Build() > at Survixel.Server.Networking.UDP.UdpServer..ctor(Int32 port) in C:\Users\alexr\Prog\C#\Survixel.Server\Survixel.Server.Networking\UDP\UdpServer.cs:line 13 > at Survixel.Server.Core.Program.Main() in C:\Users\alexr\Prog\C#\Survixel.Server\Survixel.Server.Core\Program.cs:line 10
Akronae commented 6 years ago

My bad, i had to install either Networker.Formatter.ZeroFormatter or the protobuf one, anyway I was confused this maybe should be more explicit :)

markiodev commented 6 years ago

I agree and apologise for the confusion. Need to come up with a better way to handle it without forcing a default.

markiodev commented 5 years ago

New error message included in upcoming changes.