Я пытаюсь запустить основное веб-приложение asp.net в linux, и оно работает, если я запускаю его из его каталога, но если я пытаюсь запустить его из другого каталога, я получаю NullReferenceException
из Ilogger
.
У меня определен сервис, подобный этому
public class GPIOOutput : Output
{
private ILogger<GPIOOutput> logger;
private List<IGpioPin> pins;
public GPIOOutput(IOptions<GPIOOptions> options, ILogger<GPIOOutput> logger)
:base(options.Value.Pins.Count)
{
this.logger = logger;
pins = options.Value.Pins.Select(p => Pi.Gpio[p]).ToList();
pins.ForEach(p => p.PinMode = GpioPinDriveMode.Output);
UpdateOutput();
}
protected override void UpdateOutput()
{
for (int i = 0; i < pins.Count; i++)
{
pins[i].Write(!channelData[i]);
logger.LogInformation(channelData[i].ToString());
}
}
}
, и я добавляю его так:
public static void AddGPIO(this IServiceCollection services)
{
var config = services.BuildServiceProvider().GetRequiredService<IConfiguration>();
services.AddOptions<GPIOOptions>().Bind(config.GetSection("Hardware:GPIO"));
services.AddSingleton<IOutput, GPIOOutput>();
}
Я построил проект в автономном режиме ископировать, если на мой малиновый пи. Это в /home/pi/test
. когда я запускаю его так, он работает:
pi@raspberrypi:~ $ cd test
pi@raspberrypi:~/test $ sudo ./SmartHouse --urls "http://0.0.0.0:80/"
Hosting environment: Production
Content root path: /home/pi/test
Now listening on: http://0.0.0.0:80
Application started. Press Ctrl+C to shut down.
, но если я пытаюсь из /home /pi
вот так, я получаю следующую ошибку:
pi@raspberrypi:~ $ sudo ./test/SmartHouse --urls "http://0.0.0.0:80/"
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an
at SmartHouse.RPI.GPIO.GPIOOutput..ctor(IOptions`1 options, ILogger`1 logger) in E:\Efraim's souse\SmartHouse\RPI\GPIO\GPIOOutput.cs:line 22
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstruuctorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingletnCallSite singletonCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstruuctorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingletnCallSite singletonCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstruuctorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransietCallSite transientCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerrableCallSite enumerableCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstruuctorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingletnCallSite singletonCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ISere callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__Di_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Typpe, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Typpe)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServicrovider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServicceProvider provider)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToke
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken to shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken to
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at SmartHouse.Program.Main(String[] args) in E:\Efraim's stuff\SmartHouse\SmartHouse\Program.c
Aborted