Welcome to the navigation

Cillum in incididunt magna minim amet, officia do tempor exercitation cupidatat pariatur, sit id esse qui aliqua, quis nostrud et labore mollit sed ullamco anim. Ut proident, reprehenderit eu mollit est consectetur do duis ex ipsum sunt pariatur, sint magna veniam, dolor esse irure ullamco commodo nisi culpa eiusmod ut

Yeah, this will be replaced... But please enjoy the search!

EPiServer Commerce (Mediachase) Unable to cast object of type 'System.DBNull' to type 'System.String'. after creating a new catalog

This means you (or someone) where sloppy when creating a new catalog. the error may vary but check the InvalidCastException in the stacktrace for hints. In this scenario the catalog didn't have a default language set, so removing it and adding that property when creating it solved the issue.

Method to create new EPiServer Commerce Catalog

Here is my method to create working catalog

public static bool Create(string catalogName)
        CatalogDto catalogDto1 = CatalogContext.Current.GetCatalogDto(-1, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogInfo));
        CatalogDto.CatalogRow newCatalogRow = catalogDto1.Catalog.NewCatalogRow();
        newCatalogRow.Name = catalogName;
        newCatalogRow.StartDate = DateTime.Now;
        newCatalogRow.EndDate = DateTime.Now.AddYears(20);
        newCatalogRow.IsActive = true;
        newCatalogRow.SortOrder = 0;
        newCatalogRow.ApplicationId = AppContext.Current.ApplicationId;
        newCatalogRow.Created = DateTime.Now;
        newCatalogRow.Modified = DateTime.Now;
        newCatalogRow.IsPrimary = false;
        newCatalogRow.DefaultLanguage = "sv-SE";

        // save
        return true;
        return false;

Method to delete an EPiServer Commerce Catalog

public static void Delete(string catalogName)
    CatalogDto catalogs = CatalogContext.Current.GetCatalogDto();
    CatalogDto.CatalogRow catalog = catalogs.Catalog.FirstOrDefault(x => x.Name.ToLower().Equals(catalogName.ToLower()));

The full error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'. Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

  Stack Trace:
[InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.]
   Mediachase.Commerce.Catalog.Dto.CatalogRow.get_DefaultLanguage() +80

[StrongTypingException: The value for column 'DefaultLanguage' in table 'Catalog' is DBNull.]
   Mediachase.Commerce.Catalog.Dto.CatalogRow.get_DefaultLanguage() +193
   EPiServer.Business.Commerce.HttpModules.<>c__DisplayClass1b.<GetAllCommerceLanguages>b__18(CatalogRow catalogRow) +29
   System.Collections.Generic.List`1.ForEach(Action`1 action) +76
   EPiServer.Business.Commerce.HttpModules.ProductUrlRewriteModule.GetAllCommerceLanguages() +337
   EPiServer.Business.Commerce.HttpModules.ProductUrlRewriteModule.GetProductByLink(UrlBuilder url) +729
   EPiServer.Business.Commerce.HttpModules.ProductUrlRewriteModule.UrlRewriteProvider_ConvertingToInternal(Object sender, UrlRewriteEventArgs e) +147
   EPiServer.Web.UrlRewriteProvider.OnConvertingToInternal(UrlRewriteEventArgs e) +26
   EPiServer.Web.FriendlyUrlRewriteProvider.TryConvertToInternal(UrlBuilder url, LanguageApiMode apiMode, CultureInfo& preferredCulture, Object& internalObject) +173
   EPiServer.Web.FriendlyUrlRewriteProvider.TryConvertToInternal(UrlBuilder url, CultureInfo& preferredCulture, Object& internalObject) +23
   EPiServer.Web.UrlRewriteModule.HttpUrlRewriteToInternal(UrlBuilder url) +483
   EPiServer.Web.UrlRewriteModuleBase.BeginRequestEventHandler(Object sender, EventArgs e) +205
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5420  
Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author