4.0 to 4.3 Upgrade Error. Please suggest

2 months ago
Hi All,

I upgraded from 4.0 to 4.3 (of course 4.0 to 4.1 and from 4.1 to 4.2 and from 4.2 to 4.3).

Admin panel is working fine but the public store is giving the following error:


An unhandled exception occurred while processing the request.
InvalidOperationException: Sequence contains no elements
System.Linq.ThrowHelper.ThrowNoElementsException()


Stack

InvalidOperationException: Sequence contains no elements
System.Linq.ThrowHelper.ThrowNoElementsException()
System.Linq.Enumerable.Single<TSource>(IEnumerable<TSource> source)
LinqToDB.Linq.Builder.FirstSingleBuilder+FirstSingleContext+<>c__DisplayClass5_0<T>.<GetSingleElement>b__0(IDataContext db, Expression expr, object[] ps)
LinqToDB.Linq.ExpressionQuery<T>.System.Linq.IQueryProvider.Execute<TResult>(Expression expression)
System.Linq.Queryable.Single<TSource>(IQueryable<TSource> source)
Nop.Services.Customers.CustomerService+<>c__DisplayClass70_0.<GetCustomerAddress>b__5() in CustomerService.cs
Microsoft.Extensions.Caching.Memory.CacheExtensions.GetOrCreate<TItem>(IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory)
Nop.Core.Caching.MemoryCacheManager.Get<T>(CacheKey key, Func<T> acquire) in MemoryCacheManager.cs
Nop.Services.Customers.CustomerService.GetCustomerAddress(int customerId, int addressId) in CustomerService.cs
Nop.Services.Customers.CustomerService.GetCustomerShippingAddress(Customer customer) in CustomerService.cs
Nop.Services.Tax.TaxService.PrepareTaxRateRequest(Product product, int taxCategoryId, Customer customer, decimal price) in TaxService.cs
Nop.Services.Tax.TaxService.GetTaxRate(Product product, int taxCategoryId, Customer customer, decimal price, out decimal taxRate, out bool isTaxable) in TaxService.cs
Nop.Services.Tax.TaxService.GetProductPrice(Product product, int taxCategoryId, decimal price, bool includingTax, Customer customer, bool priceIncludesTax, out decimal taxRate) in TaxService.cs
Nop.Services.Tax.TaxService.GetProductPrice(Product product, decimal price, bool includingTax, Customer customer, out decimal taxRate) in TaxService.cs
Nop.Services.Tax.TaxService.GetProductPrice(Product product, decimal price, Customer customer, out decimal taxRate) in TaxService.cs
Nop.Services.Tax.TaxService.GetProductPrice(Product product, decimal price, out decimal taxRate) in TaxService.cs
Nop.Web.Factories.ProductModelFactory.PrepareSimpleProductOverviewPriceModel(Product product, ProductPriceModel priceModel) in ProductModelFactory.cs
Nop.Web.Factories.ProductModelFactory.PrepareProductOverviewPriceModel(Product product, bool forceRedirectionAfterAddingToCart) in ProductModelFactory.cs
Nop.Web.Factories.ProductModelFactory.PrepareProductOverviewModels(IEnumerable<Product> products, bool preparePriceModel, bool preparePictureModel, Nullable<int> productThumbPictureSize, bool prepareSpecificationAttributes, bool forceRedirectionAfterAddingToCart) in ProductModelFactory.cs
Nop.Web.Components.HomepageProductsViewComponent.Invoke(Nullable<int> productThumbPictureSize) in HomepageProducts.cs
lambda_method(Closure , object , object[] )
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeSyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsync(ViewComponentContext context)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeCoreAsync(ViewComponentDescriptor descriptor, object arguments)
AspNetCore.Views_Home_Index.ExecuteAsync() in Index.cshtml
+
        @await Component.InvokeAsync("HomepageProducts")
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
WebMarkupMin.AspNetCore3.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, bool useMinification, bool useCompression)
WebMarkupMin.AspNetCore3.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, bool useMinification, bool useCompression)
WebMarkupMin.AspNetCore3.WebMarkupMinMiddlewareBase.Invoke(HttpContext context)
StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in MiniProfilerMiddleware.cs
Nop.Services.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) in AuthenticationMiddleware.cs
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Nop.Services.Installation.InstallUrlMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in InstallUrlMiddleware.cs
Nop.Services.Common.KeepAliveMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in KeepAliveMiddleware.cs
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)


Show raw exception details

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at LinqToDB.Linq.Builder.FirstSingleBuilder.FirstSingleContext.<>c__DisplayClass5_0`1.<GetSingleElement>b__0(IDataContext db, Expression expr, Object[] ps)
   at LinqToDB.Linq.ExpressionQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)
   at Nop.Services.Customers.CustomerService.<>c__DisplayClass70_0.<GetCustomerAddress>b__5() in C:\andrei\nop_sources\src\Libraries\Nop.Services\Customers\CustomerService.cs:line 1549
   at Microsoft.Extensions.Caching.Memory.CacheExtensions.GetOrCreate[TItem](IMemoryCache cache, Object key, Func`2 factory)
   at Nop.Core.Caching.MemoryCacheManager.Get[T](CacheKey key, Func`1 acquire) in C:\andrei\nop_sources\src\Libraries\Nop.Core\Caching\MemoryCacheManager.cs:line 79
   at Nop.Services.Customers.CustomerService.GetCustomerAddress(Int32 customerId, Int32 addressId) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Customers\CustomerService.cs:line 1549
   at Nop.Services.Customers.CustomerService.GetCustomerShippingAddress(Customer customer) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Customers\CustomerService.cs:line 1575
   at Nop.Services.Tax.TaxService.PrepareTaxRateRequest(Product product, Int32 taxCategoryId, Customer customer, Decimal price) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Tax\TaxService.cs:line 236
   at Nop.Services.Tax.TaxService.GetTaxRate(Product product, Int32 taxCategoryId, Customer customer, Decimal price, Decimal& taxRate, Boolean& isTaxable) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Tax\TaxService.cs:line 290
   at Nop.Services.Tax.TaxService.GetProductPrice(Product product, Int32 taxCategoryId, Decimal price, Boolean includingTax, Customer customer, Boolean priceIncludesTax, Decimal& taxRate) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Tax\TaxService.cs:line 407
   at Nop.Services.Tax.TaxService.GetProductPrice(Product product, Decimal price, Boolean includingTax, Customer customer, Decimal& taxRate) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Tax\TaxService.cs:line 379
   at Nop.Services.Tax.TaxService.GetProductPrice(Product product, Decimal price, Customer customer, Decimal& taxRate) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Tax\TaxService.cs:line 362
   at Nop.Services.Tax.TaxService.GetProductPrice(Product product, Decimal price, Decimal& taxRate) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Tax\TaxService.cs:line 347
   at Nop.Web.Factories.ProductModelFactory.PrepareSimpleProductOverviewPriceModel(Product product, ProductPriceModel priceModel) in C:\andrei\nop_sources\src\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 300
   at Nop.Web.Factories.ProductModelFactory.PrepareProductOverviewPriceModel(Product product, Boolean forceRedirectionAfterAddingToCart) in C:\andrei\nop_sources\src\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 240
   at Nop.Web.Factories.ProductModelFactory.PrepareProductOverviewModels(IEnumerable`1 products, Boolean preparePriceModel, Boolean preparePictureModel, Nullable`1 productThumbPictureSize, Boolean prepareSpecificationAttributes, Boolean forceRedirectionAfterAddingToCart) in C:\andrei\nop_sources\src\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 1115
   at Nop.Web.Components.HomepageProductsViewComponent.Invoke(Nullable`1 productThumbPictureSize) in C:\andrei\nop_sources\src\Presentation\Nop.Web\Components\HomepageProducts.cs:line 42
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeSyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsync(ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeCoreAsync(ViewComponentDescriptor descriptor, Object arguments)
   at AspNetCore.Views_Home_Index.ExecuteAsync() in C:\inetpub\wwwroot\Views\Home\Index.cshtml:line 14
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at WebMarkupMin.AspNetCore3.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore3.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore3.WebMarkupMinMiddlewareBase.Invoke(HttpContext context)
   at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 125
   at Nop.Services.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Authentication\AuthenticationMiddleware.cs:line 79
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Nop.Services.Installation.InstallUrlMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Installation\InstallUrlMiddleware.cs:line 53
   at Nop.Services.Common.KeepAliveMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in C:\andrei\nop_sources\src\Libraries\Nop.Services\Common\KeepAliveMiddleware.cs:line 50
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
2 months ago
It looks like on the public store, it is trying to display the price > which is dependent on calculating tax > which is dependent on the shipping address of the logged in customer (admin?).  Does the customer have a valid ShippingAddress_Id set in the Customer table?
2 months ago
Yes im the admin and i can confirm that I can see the ShippingAddress_ID in the customer table with a valid value.

Also I'm not sure whyit is trying to display the price > which is dependent on calculating tax > which is dependent on the shipping address of the logged in customer (admin?).

I dont remember setting this anywhere and haven't had this problem in 4.0
2 months ago
Thats just what i assumed from the call-stack in the debug. looks like .TaxService.PrepareTaxRateRequest  is calling into AddressService.GetCustomerShippingAddress and its failing somewhere around there..

I know something changed with customer addresses between 4.2 and 4.3, I'll try and find the Forum post....



mr.mourya wrote:
[i][/i]Yes im the admin and i can confirm that I can see the ShippingAddress_ID in the customer table with a valid value.

Also I'm not sure whyit is trying to display the price > which is dependent on calculating tax > which is dependent on the shipping address of the logged in customer (admin?).

I dont remember setting this anywhere and haven't had this problem in 4.0
2 months ago
I really would appreciate it mate! Will wait for your reply.
2 months ago
Can anyone please suggest on what might be the problem. I'm literally clueless.
2 months ago
JonQuick wrote:
it is trying to display the price > which is dependent on calculating tax > which is dependent on the shipping address of the logged in customer

This is not a setting its just the way it works

Just looking at the Address table the structure does not seem to have changed from v4.0 to v4.3. The way the system uses the address has changed for v4.3 not to get too technical.
Although in theory the update should have fixed any issues but seems there may have been a problem.

Anyway if admin works you could go into your customer record and edit the Address and save. Maybe this will fix any data errors. Then see if you can go into the front end.
2 months ago
Change the address for every user? Not sure how many customers would have this issue. Let me try and reply back.
2 months ago
If a 're-saved' address works as suggested, then try and compare (at SQL level) the different values between working and failing customer address

Then maybe (backing up database first) we can write a SQL query to correct the issue across all records.

mr.mourya wrote:
Change the address for every user? Not sure how many customers would have this issue. Let me try and reply back.
2 months ago
mr.mourya wrote:
Yes im the admin and i can confirm that I can see the ShippingAddress_ID in the customer table with a valid value....

Is there a record in the CustomerAddresses table where its Address_Id = ShippingAddress_ID and Customer_Id =  the customer's Id?

CustomerService  GetCustomerAddress()
var query = from address in _customerAddressRepository.Table
                join cam in _customerAddressMappingRepository.Table on address.Id equals cam.AddressId
                where cam.CustomerId == customerId && address.Id == addressId
                select address;