DXP Cloud Setup First Time Issue

Vote:
 

So I am working through the example here.

https://docs.developers.optimizely.com/digital-experience-platform/v1.2.0-dxp-cloud-services/docs/creating-a-new-cms-site-and-deploying

Seems simple enough.  I'm in Step 1... item 4.  

  1. To configure the EPiServer.CloudPlatform.Cms package, add this code in ConfigureServices method in startup.cs file.
public class Startup
{
    public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        ...
        services.AddCmsCloudPlatformSupport(configuration);
    }
}

After I do this, I can no longer run the project.   I get this error.

'']

Not sure how to resolve?

#295736
Edited, Feb 01, 2023 19:19
Vote:
 

The call from Main in program.cs is a delegate to the ConfigureServices so that call must match. Simplest way to fix this is to remove IConfiguration from that parameter and inject it in the startup constructor instead.

e.g.

public class Startup
{
    private readonly IConfiguration Configuration;
    
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddCmsCloudPlatformSupport(Configuration);
    }
}
#295739
Feb 01, 2023 19:42
Vote:
 

Now I get a different error.   The CMS was loading before I applied the changes.   This is just the base empty Optimizely site.

#295742
Feb 01, 2023 20:17
Vote:
 

So unlike my first suspicion, this is probably caused by AddCmsCloudPlatformSupport since you try to run it in your dev environment?

if (!_webHostingEnvironment.IsDevelopment())
{
    services.AddCmsCloudPlatformSupport(Configuration);
}

Ensure IWebHostEnvironment is injected in the constructor

The AddCmsCloudPlatformSupport only adds cloud related stuff. You can probably use it locally as well as long as all your services are configured locally.

A complete startup.cs example

public class Startup
{
    private readonly IWebHostEnvironment _webHostingEnvironment;

    private readonly IConfiguration Configuration;

    public Startup(IWebHostEnvironment webHostingEnvironment, IConfiguration configuration)
    {
        _webHostingEnvironment = webHostingEnvironment;
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        if (_webHostingEnvironment.IsDevelopment())
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_webHostingEnvironment.ContentRootPath, "App_Data"));

            services.Configure<SchedulerOptions>(options => options.Enabled = false);
        }

        services
            .AddCmsAspNetIdentity<ApplicationUser>()
            .AddCommerce()
            .AddAdminUserRegistration()
            .AddEmbeddedLocalization<Startup>();

        if (!_webHostingEnvironment.IsDevelopment())
        {
            services.AddCmsCloudPlatformSupport(Configuration);
        }
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseAnonymousId();

        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapContent();
        });
    }
}
#295744
Edited, Feb 01, 2023 20:48
Vote:
 

I am still getting the same error - same line.  My connectionstring is in appsettings.Development.json.   It's just the initial install.   Yes, I am trying to run the project locally.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "EPiServer": "Information",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "ConnectionStrings": {
    "EPiServerDB": "Data Source=(LocalDb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\dxp-cloud-test.mdf;Initial Catalog=dxp-cloud-test;Integrated Security=True;Connect Timeout=30"
  },
  "EPiServer": {
    "Cms": {
      "MappedRoles": {
        "Items": {
          "CmsEditors": {
            "MappedRoles": [ "WebEditors", "WebAdmins" ]
          },
          "CmsAdmins": {
            "MappedRoles": [ "WebAdmins" ]
          }
        }
      }
    }
  }
}

This is my current Startup.cs

public class Startup
{
    private readonly IWebHostEnvironment _webHostingEnvironment;
    private readonly IConfiguration Configuration;

    public Startup(IWebHostEnvironment webHostingEnvironment, IConfiguration configuration)
    {
        _webHostingEnvironment = webHostingEnvironment;
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        if (_webHostingEnvironment.IsDevelopment())
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_webHostingEnvironment.ContentRootPath, "App_Data"));
            services.Configure<SchedulerOptions>(options => options.Enabled = false);
        }

        services
            .AddCmsAspNetIdentity<ApplicationUser>()
            .AddCms()
            .AddAdminUserRegistration()
            .AddEmbeddedLocalization<Startup>();

        if (_webHostingEnvironment.IsDevelopment())
        {
            services.AddCmsCloudPlatformSupport(Configuration);
        }

    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapContent();
        });
    }
}
#295745
Feb 01, 2023 20:58
Eric Herlitz - Feb 01, 2023 21:13
Accidently pasted my code with a bug, was missing the ! in the environment condition 🤦‍♂️

if (!_webHostingEnvironment.IsDevelopment())
{
services.AddCmsCloudPlatformSupport(Configuration);
}
Vote:
 

Okay now it works thanks...  looks like those instructions need to be updated.

Not too familiar with webHostingEnvironment parameters, is that line going to be an issue when I try and push to Integration environment?

if (!_webHostingEnvironment.IsDevelopment())
{
services.AddCmsCloudPlatformSupport(Configuration);
}
#295751
Feb 01, 2023 21:22
Eric Herlitz - Feb 01, 2023 21:30
Shouldn't be an issue unless the integration environment is set up to use the development configuration
Eric Herlitz - Feb 02, 2023 8:42
I've updated my previous post with the correct configuration, please set it as the accepted answer in order to help the next person with this issue.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.