AppHostBase.Instance has already been set exception after uCommerce upgrade
Hi guys
I'm trying to upgrade a Umbraco v4.11.8 installation that uses uCommerce v3.6.0.13142 (and the uCommerce Demo Store - Razor 1.0.3.13124) to uCommerce v6.0.0.14094 and I'm hitting a bit of a brick wall. Here is the exception I'm receving after installing the package through Umbraco (without uninstalling the previous version of uCommerce):
Looking into the exception, it seems like something to do with ServiceStack and the uCommerce web API. We're not currently using ServiceStack in our project or any classes that derive from AppHostBase, so I'm a bit stuck. Any help or advice would be greatly appreciated!
Currently have the issue running IIS Express 8.0, Cassini / Visual Studio 2012 and IIS 7.5.
The thing is that in version 5 we pulled in Service Stack so now version 1 of the demo store and version 5 and up, competes With ServiceStack (only one instance can be set). You can try to compile an assembly of the demo store that doesn't open ServiceStack and deploy it before you update.
Those are the two ways to get your application back up and running. Please note that you need the newest version of the demo store OR remove the part that starts up ServiceStack and recompile the existing demo store and deploy it.
Cheers Morten; Rigardt how I essentially got it working was the below:
Download both the latest version of uCommerce and the Razor Store.
Open up two tabs on your browser of choice, both pointing to the install local packages on the developer tab of Umbraco.
Make a copy of all your macro scripts. The fresh install of the Razor Store will overwrite them.
Install the latest version of uCommerce, and then the Razor Store using the two tabs you set up. This will help avoid the above issue and the whole chicken and egg scenario this issue presents.
Don't forget to merge in any custom pipelines or services with the new configuration files. There will be backup of them in the ucommerce folder.
I've only had time to currently test this on a site that has been heavily modifed from the default Razor Store, and as such, a fair few things have broke, but hopefully this should get you somewhere.
Thanks for the response. Since my Razor Store was also heavily modified, I went with the option of amending its source to be compatible with the latest uCommerce since this was the safer option in my case. For those interested in the changes I made to the Razor Store source code to get the it working again, please see below:
Umbraco 4.11.10, uCommerce 6.0.1.14120, uCommerce Demo Store - Razor 1.0.3.13143
uCommerce.RazorStore source code changes:
1) Fix the original "AppHostBase.Instance has already been set" error: Exclude uCommerceApiAppHost and uCommerceApiRegistration from the solution. As Morten have said, this will prevent the store from creating its own ServiceStack instance now that uCommerce is already doing this.
At this stage, the store web service calls (e.g. AddToBasket) will return 404 errors.
2) Reference the correct ServiceStack and uCommerce assemblies: The store was using ServiceStack 3.78 which is replaced by ServiceStack 3.9.55 in uCommerce 6.0.1. Remove all ServiceStack references from the store and grab the following assemblies from your Umbraco site where you've installed uCommerce and reference them instead:
Ensure you're namespaces are correct in case they're different from mine. This will fix the 404 errors, but the web service calls will now be returning 405 errors.
4) Fix the store web services: The store consists of 6 web services at UCommerce.RazorStore.Services.Commands:
public class AddToBasketService : ServiceStack.ServiceInterface.Service
{
public AddToBasketResponse Post(AddToBasket request)
{
TransactionLibrary.AddToBasket(request.Quantity, request.Sku, request.VariantSku, request.AddToExistingLine, true, request.CatalogId);
return new AddToBasketResponse();
}
}
.
public class GetBasketService : ServiceStack.ServiceInterface.Service
{
public GetBasketResponse Post(GetBasket request)
{
var basket = TransactionLibrary.GetBasket(false);
return new GetBasketResponse(basket);
}
}
.
public class GetProductVariationsService : ServiceStack.ServiceInterface.Service
{
public GetProductVariationsResponse Post(GetProductVariations request)
{
var product = CatalogLibrary.GetProduct(request.ProductSku);
return new GetProductVariationsResponse(product);
}
}
.
public class GetVariantSkuFromSelectionService : Service
{
public GetVariantSkuFromSelectionResponse Post(GetVariantSkuFromSelection request)
{
var product = CatalogLibrary.GetProduct(request.ProductSku);
return new GetVariantSkuFromSelectionResponse(product, request.VariantProperties);
}
}
.
public class SearchService : Service
{
public SearchResponse Post(Search request)
{
var products = EntitiesV2.Product.Find(p =>
p.VariantSku == null
&& p.DisplayOnSite &&
(
p.Sku.Contains(request.Keyword)
|| p.Name.Contains(request.Keyword)
||
p.ProductDescriptions.Any(
d =>
d.DisplayName.Contains(request.Keyword) || d.ShortDescription.Contains(request.Keyword) ||
d.LongDescription.Contains(request.Keyword))
)
);
return new SearchResponse(products);
}
}
.
public class UpdateLineItemService : ServiceStack.ServiceInterface.Service
{
public UpdateLineItemResponse Post(UpdateLineItem request)
{
TransactionLibrary.UpdateLineItem(request.OrderLineId, request.NewQuantity);
TransactionLibrary.ExecuteBasketPipeline();
var newLine = TransactionLibrary.GetBasket().PurchaseOrder.OrderLines.FirstOrDefault(l => l.OrderLineId == request.OrderLineId);
return new UpdateLineItemResponse(newLine);
}
}
Apart from using the correct references, the rest of each of these files can stay the same.
5) Compile a new version of UCommerce.RazorStore.dll and drop it into the Umbraco bin.
I think this was all the steps required in my case to get V1 of the Razor Store compatible with V6 of uCommerce.
Good stuff Rigardt, might end up trying that approach in the end - I'm having a couple of issues now regarding applying discounts:
I've created a discount which acts on the entire product catalog, which awards an Amount off order total. When the discount is applied through the standard basket pipline (UCommerce.Pipelines.Basket.BasketPipeline - vanilla, no custom components), an exception is thrown. What is weird is that there is only one VAT rate / Pricegroup on the site, and all products are using it.
UCommerce.Piplines.PiplineException - Purchase order VAT cannot be accurately calculated when using different VAT rate per item combined with order level discounts. Make sure that any Awards apply to all order lines when differentiated VAT is being used by using extension method PurchaseOrder.UsesDifferentiatedVat() in your Award's Apply method.
Stack trace:
at UCommerce.Pipelines.Pipeline`1.Execute(T subject)
at UCommerce.Transactions.TransactionLibraryInternal.ExecuteOrderPipeline(String pipelineName)
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteOrderPipeline_callback(String pipelineName)
at Castle.Proxies.Invocations.TransactionLibraryInternal_ExecuteOrderPipeline.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteOrderPipeline(String pipelineName)
at UCommerce.Transactions.TransactionLibraryInternal.ExecuteBasketPipeline()
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteBasketPipeline_callback()
at Castle.Proxies.Invocations.TransactionLibraryInternal_ExecuteBasketPipeline.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteBasketPipeline()
at ASP.uCommerce.Functions.Basket.AddToBasket(String addToBasketKey, String quantityKey, Product variant) in f:\PH-Creative\Sites\Danz\Umbraco\App_Code\uCommerce\Functions\Basket.cshtml:line 25
at ASP._Page_macroScripts_uCommerce_Product_cshtml.Execute() in f:\PH-Creative\Sites\Danz\Umbraco\macroScripts\uCommerce\Product.cshtml:line 563
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
uCommerce is detecting a "differentiated line tax"-scenario. Basically this happens when the VATRate of order lines is different. If you are creating new order lines on the fly you want to make sure that they all have the same VATRate assigned.
If you are indeed working with differentiated tax per line read on for more details around how to handle it:
The reason uCommerce specifically looks for this case is that order level discounts cannot be supported as it would prevent reliably calculating tax for the entire order.
What you want to do in this case is split the order level discount across all the order lines on the order. This is done by assigning the discount to all available order lines like so:
foreach (var orderline in orderlines) { orderline.AddDiscount(myDiscount); }
uCommerce will automatially add your discount into the totals of individual order lines so you don't have to worry about that.
As mentioned it's only required for diff. tax scenarios, so you only need to apply it in this instance.
You can detect diff tax using an extension method on the order called:
AppHostBase.Instance has already been set exception after uCommerce upgrade
Hi guys
I'm trying to upgrade a Umbraco v4.11.8 installation that uses uCommerce v3.6.0.13142 (and the uCommerce Demo Store - Razor 1.0.3.13124) to uCommerce v6.0.0.14094 and I'm hitting a bit of a brick wall. Here is the exception I'm receving after installing the package through Umbraco (without uninstalling the previous version of uCommerce):
Looking into the exception, it seems like something to do with ServiceStack and the uCommerce web API. We're not currently using ServiceStack in our project or any classes that derive from AppHostBase, so I'm a bit stuck. Any help or advice would be greatly appreciated!
Currently have the issue running IIS Express 8.0, Cassini / Visual Studio 2012 and IIS 7.5.
Cheers
Mike
The thing is that in version 5 we pulled in Service Stack so now version 1 of the demo store and version 5 and up, competes With ServiceStack (only one instance can be set). You can try to compile an assembly of the demo store that doesn't open ServiceStack and deploy it before you update.
Hi Mike
I am experiencing the same problem as you've mentioned above - did you manage to solve it at the end?
Best regards,
Rigardt
Please refer to the following two articles:
http://docs.ucommerce.net/ucommerce/v5/extending-ucommerce/add-a-new-web-service/index.html
http://docs.ucommerce.net/ucommerce/v5/extending-ucommerce/add-a-new-web-service/how-to-create-a-basket-web-service.html
Those are the two ways to get your application back up and running. Please note that you need the newest version of the demo store OR remove the part that starts up ServiceStack and recompile the existing demo store and deploy it.
Hope that helps.
Cheers Morten; Rigardt how I essentially got it working was the below:
Download both the latest version of uCommerce and the Razor Store.
Open up two tabs on your browser of choice, both pointing to the install local packages on the developer tab of Umbraco.
Make a copy of all your macro scripts. The fresh install of the Razor Store will overwrite them.
Install the latest version of uCommerce, and then the Razor Store using the two tabs you set up. This will help avoid the above issue and the whole chicken and egg scenario this issue presents.
Don't forget to merge in any custom pipelines or services with the new configuration files. There will be backup of them in the ucommerce folder.
I've only had time to currently test this on a site that has been heavily modifed from the default Razor Store, and as such, a fair few things have broke, but hopefully this should get you somewhere.
Hi Mike
Thanks for the response. Since my Razor Store was also heavily modified, I went with the option of amending its source to be compatible with the latest uCommerce since this was the safer option in my case. For those interested in the changes I made to the Razor Store source code to get the it working again, please see below:
Umbraco 4.11.10, uCommerce 6.0.1.14120, uCommerce Demo Store - Razor 1.0.3.13143
uCommerce.RazorStore source code changes:
1) Fix the original "AppHostBase.Instance has already been set" error: Exclude uCommerceApiAppHost and uCommerceApiRegistration from the solution. As Morten have said, this will prevent the store from creating its own ServiceStack instance now that uCommerce is already doing this.
At this stage, the store web service calls (e.g. AddToBasket) will return 404 errors.
2) Reference the correct ServiceStack and uCommerce assemblies: The store was using ServiceStack 3.78 which is replaced by ServiceStack 3.9.55 in uCommerce 6.0.1. Remove all ServiceStack references from the store and grab the following assemblies from your Umbraco site where you've installed uCommerce and reference them instead:
ServiceStack.dll (3.9.55), ServiceStack.Interfaces.dll (3.9.55), ServiceStack.ServiceInterface.dll (3.9.55)
Also grab UCommerce.Web.Api.dll (v6)
3) Register IContainsWebservices according to http://docs.ucommerce.net/ucommerce/v5/extending-ucommerce/add-a-new-web-service/index.html:
Add AssemblyTag.cs to the solution with the following content:
In Umbraco, update the uCommerce Custom.config by adding the following component:
Ensure you're namespaces are correct in case they're different from mine. This will fix the 404 errors, but the web service calls will now be returning 405 errors.
4) Fix the store web services: The store consists of 6 web services at UCommerce.RazorStore.Services.Commands:
AddToBasket, GetBasket, GetProductVariations, GetVariantSkuFromSelection, Search, UpdateLineItem
For each of these, amend it according to http://docs.ucommerce.net/ucommerce/v5/extending-ucommerce/add-a-new-web-service/how-to-create-a-basket-web-service.html. Below, I've included my final versions of the main web service class snippets for each of these:
.
.
.
.
.
Apart from using the correct references, the rest of each of these files can stay the same.
5) Compile a new version of UCommerce.RazorStore.dll and drop it into the Umbraco bin.
I think this was all the steps required in my case to get V1 of the Razor Store compatible with V6 of uCommerce.
Rigardt
Good stuff Rigardt, might end up trying that approach in the end - I'm having a couple of issues now regarding applying discounts:
I've created a discount which acts on the entire product catalog, which awards an Amount off order total. When the discount is applied through the standard basket pipline (UCommerce.Pipelines.Basket.BasketPipeline - vanilla, no custom components), an exception is thrown. What is weird is that there is only one VAT rate / Pricegroup on the site, and all products are using it.
UCommerce.Piplines.PiplineException - Purchase order VAT cannot be accurately calculated when using different VAT rate per item combined with order level discounts. Make sure that any Awards apply to all order lines when differentiated VAT is being used by using extension method PurchaseOrder.UsesDifferentiatedVat() in your Award's Apply method.
Stack trace:
at UCommerce.Pipelines.Pipeline`1.Execute(T subject)
at UCommerce.Transactions.TransactionLibraryInternal.ExecuteOrderPipeline(String pipelineName)
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteOrderPipeline_callback(String pipelineName)
at Castle.Proxies.Invocations.TransactionLibraryInternal_ExecuteOrderPipeline.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteOrderPipeline(String pipelineName)
at UCommerce.Transactions.TransactionLibraryInternal.ExecuteBasketPipeline()
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteBasketPipeline_callback()
at Castle.Proxies.Invocations.TransactionLibraryInternal_ExecuteBasketPipeline.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.ExecuteBasketPipeline()
at UCommerce.Transactions.TransactionLibraryInternal.AddToBasket(String catalogName, Int32 quantity, String sku, String variantSku, Boolean addToExistingLine, Boolean executeBasketPipeline)
at Castle.Proxies.TransactionLibraryInternalProxy.AddToBasket_callback(String catalogName, Int32 quantity, String sku, String variantSku, Boolean addToExistingLine, Boolean executeBasketPipeline)
at Castle.Proxies.Invocations.TransactionLibraryInternal_AddToBasket.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.AddToBasket(String catalogName, Int32 quantity, String sku, String variantSku, Boolean addToExistingLine, Boolean executeBasketPipeline)
at UCommerce.Api.TransactionLibrary.AddToBasket(Int32 quantity, String sku, String variantSku, Boolean addToExistingLine, Boolean executeBasketPipeline, Nullable`1 catalogId)
at ASP.uCommerce.Functions.Basket.AddToBasket(String addToBasketKey, String quantityKey, Product variant) in f:\PH-Creative\Sites\Danz\Umbraco\App_Code\uCommerce\Functions\Basket.cshtml:line 25
at ASP._Page_macroScripts_uCommerce_Product_cshtml.Execute() in f:\PH-Creative\Sites\Danz\Umbraco\macroScripts\uCommerce\Product.cshtml:line 563
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Hi Mike. Unfortunately I can't say I've seen that one in my upgrade process. It sounds like one for uCommerce :)
Hi Mike,
uCommerce is detecting a "differentiated line tax"-scenario. Basically this happens when the VATRate of order lines is different. If you are creating new order lines on the fly you want to make sure that they all have the same VATRate assigned.
If you are indeed working with differentiated tax per line read on for more details around how to handle it:
The reason uCommerce specifically looks for this case is that order level discounts cannot be supported as it would prevent reliably calculating tax for the entire order.
What you want to do in this case is split the order level discount across all the order lines on the order. This is done by assigning the discount to all available order lines like so:
uCommerce will automatially add your discount into the totals of individual order lines so you don't have to worry about that.
As mentioned it's only required for diff. tax scenarios, so you only need to apply it in this instance.
You can detect diff tax using an extension method on the order called:
Hope this helps.
is working on a reply...