Closed bbmmcodegirl closed 3 weeks ago
The NRE happens in this code:
[Event(ServiceCallStartId, Keywords = Keywords.Services, Message = ServiceCallStartMessage, Level = EventLevel.Verbose, Task = Tasks.ServiceCallTask)]
public void ServiceCallStart(string serviceName, int requestHandle, int pendingRequestCount)
{
if (IsEnabled())
{
WriteEvent(ServiceCallStartId, serviceName, requestHandle, pendingRequestCount);
}
else if (Utils.Logger.IsEnabled(LogLevel.Trace)) <------ Utils.Logger is null.
{
Utils.Log(LogLevel.Trace, ServiceCallStartEventId, ServiceCallStartMessage, serviceName, requestHandle, pendingRequestCount);
}
}
The library should obviously be resilient against such a case.
Hi @bbmmcodegirl, thanks for the report. My suggestion is to use the Opc.Ua.Configuration library to build theconfiguration with the fluent API or to use the file API to load the configuration. They ensure all is properly configured. Utils.Logger is used across the board and having null checks all over the place adds quite some overhead that can be avoided. I suggest to initialize it properly.
Type of issue
Current Behavior
Opening a client session, Synchronous
Open()
, throws aNullReferenceException
in a logging function. The session is not opened.Expected Behavior
The session should open (if the server allows anonymous access and SecurityPolicy None) and not throw an exception.
Steps To Reproduce
OPCFoundation.NetStandard.Opc.Ua.Client
Version 1.5.374.126 andOPCFoundation.NetStandard.Opc.Ua.Core
Version 1.5.374.126.ServerUrl
variable to have some useful value.SecurityPolicy
None and listens on thatServerUrl
. But I suspect that the call does not even go to the actual connection, so you may not need a server running.The
Open
call will throw aNullReferenceException
from a logging method, of all things.Environment
Anything else?
This is how the session is created:
The configuration that is passed in looks something like tis: