0

I've got a set of interfaces doing inheritance as follows (trimmed for essentials):

public interface IGlassBase

public interface IMetaData : IGlassBase

public interface IBaseHubPage : IMetaData

public interface IHomePage : IBaseHubPage

Then in the mapping classes, I have the following (again trimmed for essentials):

public class GlassBaseMap : SitecoreGlassMap<IGlassBase> {
  public override void Configure() {
    Map(config => ... }
  }

public class MetaDataMap : SitecoreGlassMap<IMetaData> {
  public override void Configure() {
    Map(config => { ImportMap<IGlassBase>(); }
  }

public class BaseHubPageMap : SitecoreGlassMap<IBaseHubPage> {
  public override void Configure() {
    Map(config => { ImportMap<IMetaData>(); }
  }

public class HomePageMap : SitecoreGlassMap<IHomePage> {
  public override void Configure() {
    Map(config => { ImportMap<BaseHubPageMap>(); }
  }

And for importing the maps in the GlassMapperScCustom file, I have this:

public static void AddMaps(IConfigFactory<IGlassMap> mapsConfigFactory) {
  string binPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin");

  foreach (string dll in Directory.GetFiles(binPath, "Client*.dll", SearchOption.AllDirectories)) {
    try {
      Assembly loadedAssembly = Assembly.LoadFile(dll);
      Type glassmapType = typeof(IGlassMap);
      var maps = loadedAssembly.GetTypes().Where(x => glassmapType.IsAssignableFrom(x));

      if (maps != null) {
        foreach (var map in maps) {
          mapsConfigFactory.Add(() => Activator.CreateInstance(map) as IGlassMap);
        }
      }
    } catch (FileLoadException loadEx) {
    } // The Assembly has already been loaded.
    catch (BadImageFormatException imgEx) {
    } // If exception is thrown, the file is not an assembly.
  }
}

Everything works fine if I keep the HomePageMap out of the mix, but when I add it back in, I get this error: Could not find the configuration for type Client.Website.Models.Configuration.BaseHubPageMap. Is there an inheritance limit I'm hitting to prevent this from working right, or some other import or configuration process I need to do?

1 Answer 1

2

For HomePageMap, your ImportMap call is importing the map (BaseHubPageMap) rather than the interface.

So change that map to be:

public class HomePageMap : SitecoreGlassMap<IHomePage> {
  public override void Configure() {
    Map(config => { ImportMap<IBaseHubPage>(); }
  }
2
  • Yep, I got a compilation to go after that. Thanks for the eyes, I just mixed-and-matched! Mar 31, 2017 at 18:19
  • no problem! Additional pairs of eyes are always helpful. Mar 31, 2017 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.