Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

code generation - Sitecore Glass Mapper always null

I am using Sitecore Glass Mapper for a new project I'm setting up. We are using Sitecore 7.2, latest version of Team Development for Sitecore (TDS) code generation and the latest version of glass.

The code I am trying to execute:

var b = new SitecoreContext();
var c = b.GetCurrentItem<T01_Homepage>();

b is not null. c is null.

var d = b.GetItem<T01_Homepage>("path")

d is null.

I added my assembly in GlassMapperScCustom:

public static IConfigurationLoader[] GlassLoaders(){            

    var attributes = new AttributeConfigurationLoader(new[] { "Company.Framework.Websites.Corporate", "Company.Framework.Core", "Company.Framework.Common" });

    return new IConfigurationLoader[] { attributes };
}

When I look into b.GlassContext.TypeConfigurations all my models are there.

I figured it could be a language issue because the site is in dutch and maybe the wrong language would be resolved incorrectly. This was also not the case.

I disabled WebActivator and added the GlassMapperSc.Start() in my Global.asax Application_Start method.

We are also using Autofac as DI framework. But without it, it still isn't working as you can see above. Also when I create my own custom models without TDS code generation the result of GetCurrentItem<T> is null.

Does anyone have an idea how I can fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Did you check your Sites.config and the default language for this website? There could be a difference between the language which is defined in your Sitecore languages folder and your configuration.

I had a similar problem with one of my projects where I changed the Sitecore.Context.Language to "nl" instead of "nl-NL". The glass mapper will return null, but Sitecore.Context.Database.GetItem will return an object in this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...