System.NullReferenceException: 'Object reference not set to an instance of an object.'
SoftPro.Select.Service.Runtime.RuntimeContext.CurrentSessionToken.get returned null.
In previous work sessions, CurrentSessionToken was not null. I'm not sure what caused it to become null. Is there anything that I could have possibly done on my end to make this so? Is there any way to reimplement the CurrentSessionToken?
CurrentSessionToken is null
Moderator: Phil Barton
-
- Posts: 23
- Joined: Wed Jul 12, 2023 11:29 am
Re: CurrentSessionToken is null
Is this code in a server package or something else? Is there a code snippet you could share?
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: CurrentSessionToken is null
In order to help, please provide the code for the area that is failing and the complete call stack. Thanks.
Bob Richards, Senior Software Developer, SoftPro
Re: CurrentSessionToken is null
This is in a server package that I'm running in debug mode
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception is System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at SoftPro.ClientModel.Linq.Evaluator.SubtreeEvaluator.Evaluate(Expression e) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\Evaluator.cs:line 85
at SoftPro.ClientModel.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\ExpressionVisitor.cs:line 153
at SoftPro.ClientModel.Linq.ExpressionVisitor.VisitLambda(LambdaExpression lambda) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\ExpressionVisitor.cs:line 393
at SoftPro.ClientModel.Linq.Evaluator.PartialEval(Expression expression, Func`2 fnCanBeEvaluated) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\Evaluator.cs:line 22
at SoftPro.ClientModel.Linq.CombineWhereVisitor.CombineWhereExpression(MethodCallExpression expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CombineWhereVisitor.cs:line 27
at SoftPro.ClientModel.Linq.CriteriaBuilder`2.HandleWhereExpression(Expression expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaBuilder.cs:line 196
at SoftPro.ClientModel.Linq.CriteriaBuilder`2.Build(Expression& expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaBuilder.cs:line 143
at SoftPro.ClientModel.Linq.CriteriaQueryProvider`2.Execute(Expression expression, Boolean enumerable) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaQueryProvider.cs:line 110
at SoftPro.ClientModel.Linq.CriteriaQueryProvider`2.Execute[TResult](Expression expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaQueryProvider.cs:line 64
at SoftPro.Select.Server.Runtime.SessionManager.GetSession(ISessionToken original) in D:\a\1\s\Code\SPNet\Select\SelectServer\Runtime\SessionManager.cs:line 513
at SoftPro.Select.Server.Runtime.SessionManager.CloneToken(ISessionToken original) in D:\a\1\s\Code\SPNet\Select\SelectServer\Runtime\SessionManager.cs:line 460
at SoftPro.Select.Service.Runtime.RuntimeContext.Impersonate(ISessionToken token, Boolean clone) in D:\a\1\s\Code\SPNet\Select\SelectService\Runtime\RuntimeContext.cs:line 131
at BendunExtension.BendunExtension.<SaveOrders>d__2.MoveNext() in C:\Users\garli\source\repos\BendunExtension\BendunExtension\BendunExtension.cs:line 97
Code: Select all
using (RuntimeContext.Impersonate(RuntimeContext.CurrentSessionToken, true))
{
// Set default profile.
IProfileManager pm = GetService<IProfileManager>();
IProfileInfo pi = pm.Profiles.Where(t => t.Name == "Default").FirstOrDefault();
IProfile profile = pm.GetProfile(pi);
pm.ActiveProfile = profile;
IOrderStore os = GetService<IOrderStore>();
System.Diagnostics.Debug.WriteLine($"order length {orders.Length}");
for (int i = 0; i < orders.Length; i++)
{
// Fetch a new order from the order store.
var spec = new OrderCreationSpec();
spec.SettlementType = SettlementType.CDF;
IOrder order = os.NewOrder(spec);
// Cast to dynamic to make order handling easier.
dynamic o = (dynamic)order;
// Set a property.
o.Project = "Bendun";
o.Properties.Parcels.Identification = orders[i].TaxParcel;
o.SettlementLocation.Place.Address.Address1 = orders[i].Address1;
o.SettlementLocation.Place.Address.Address2 = orders[i].Address2;
o.SettlementLocation.Place.Address.City = orders[i].City;
o.SettlementLocation.Place.Address.Zip = orders[i].Zip;
o.SettlementLocation.Place.Address.County = orders[i].County;
// Get IState object.
IEnumManager enumMgr = GetService<IEnumManager>();
IState state = enumMgr.GetEnum<IState>().Values.Where(t => t.Code == orders[i].State).First();
o.SettlementLocation.Place.Address.State = state;
// Save the order in the database.
os.ApplyChanges(order);
orderIds.Add(orders[i].idSearchOrder);
}
}
Exception is System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at SoftPro.ClientModel.Linq.Evaluator.SubtreeEvaluator.Evaluate(Expression e) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\Evaluator.cs:line 85
at SoftPro.ClientModel.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\ExpressionVisitor.cs:line 153
at SoftPro.ClientModel.Linq.ExpressionVisitor.VisitLambda(LambdaExpression lambda) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\ExpressionVisitor.cs:line 393
at SoftPro.ClientModel.Linq.Evaluator.PartialEval(Expression expression, Func`2 fnCanBeEvaluated) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\Evaluator.cs:line 22
at SoftPro.ClientModel.Linq.CombineWhereVisitor.CombineWhereExpression(MethodCallExpression expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CombineWhereVisitor.cs:line 27
at SoftPro.ClientModel.Linq.CriteriaBuilder`2.HandleWhereExpression(Expression expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaBuilder.cs:line 196
at SoftPro.ClientModel.Linq.CriteriaBuilder`2.Build(Expression& expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaBuilder.cs:line 143
at SoftPro.ClientModel.Linq.CriteriaQueryProvider`2.Execute(Expression expression, Boolean enumerable) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaQueryProvider.cs:line 110
at SoftPro.ClientModel.Linq.CriteriaQueryProvider`2.Execute[TResult](Expression expression) in D:\a\1\s\Code\SPNet\Models\ClientModel\Linq\CriteriaQueryProvider.cs:line 64
at SoftPro.Select.Server.Runtime.SessionManager.GetSession(ISessionToken original) in D:\a\1\s\Code\SPNet\Select\SelectServer\Runtime\SessionManager.cs:line 513
at SoftPro.Select.Server.Runtime.SessionManager.CloneToken(ISessionToken original) in D:\a\1\s\Code\SPNet\Select\SelectServer\Runtime\SessionManager.cs:line 460
at SoftPro.Select.Service.Runtime.RuntimeContext.Impersonate(ISessionToken token, Boolean clone) in D:\a\1\s\Code\SPNet\Select\SelectService\Runtime\RuntimeContext.cs:line 131
at BendunExtension.BendunExtension.<SaveOrders>d__2.MoveNext() in C:\Users\garli\source\repos\BendunExtension\BendunExtension\BendunExtension.cs:line 97
Re: CurrentSessionToken is null
Just for clarification, line 97 is the using statement where things are breaking.
Re: CurrentSessionToken is null
you can try using just an empty Impersonate block
I'm not going to pretend to fully understand what all the Impersonate blocks do, but from what I've been able to gather, it has something to do with threading and if the action that triggered the block of code running originated from the UI.
Code: Select all
using (RuntimeContext.Impersonate())
Vlad Mrvichin, Senior Software Developer, Custom Dev, SoftPro
Re: CurrentSessionToken is null
Thanks, this worked perfectly!