This fails as soon as I try to create a SitecoreContext, accessing this property in my AbstractGlassWebControl class:Context has not been loaded
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: Glass.Sitecore.Mapper.MapperException: Context has not been loaded
Source Error:
Line 239:
Line 240: //due to changes in the way that handlers are created we should no longer need to clone the instance context
Line 241: return StaticContext; //.Clone() as InstanceContext;
Line 242: }
Line 243:
Source File: c:\clientWork\Glass\Source\Glass.Sitecore.Mapper\Context.cs Line: 241
Stack Trace:
[MapperException: Context has not been loaded]
Glass.Sitecore.Mapper.Context.GetContext() in c:\clientWork\Glass\Source\Glass.Sitecore.Mapper\Context.cs:241
Glass.Sitecore.Mapper.SitecoreService..ctor(Database database) in c:\clientWork\Glass\Source\Glass.Sitecore.Mapper\SitecoreService.cs:56
Glass.Sitecore.Mapper.SitecoreContext..ctor() in c:\clientWork\Glass\Source\Glass.Sitecore.Mapper\SitecoreContext.cs:27
Glass.Sitecore.Mapper.Web.Ui.AbstractGlassWebControl.get_SitecoreContext() in c:\clientWork\Glass\Source\Glass.Sitecore.Mapper\Web\Ui\AbstractGlassWebControl.cs:19
Glass.Sitecore.Mapper.Web.Ui.GlassWebControl`1.OnLoad(EventArgs e) in c:\clientWork\Glass\Source\Glass.Sitecore.Mapper\Web\Ui\GlassWebControl.cs:16
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
public ISitecoreContext SitecoreContext
{
get { return _sitecoreContext ?? (_sitecoreContext = new SitecoreContext()); }
set { _sitecoreContext = value; }
}
public abstract class GlassWebControl<T> : AbstractGlassWebControl where T : class
{
protected override void OnLoad(EventArgs e)
{
Model = SitecoreContext.CreateClass<T>(false, false, LayoutItem);
base.OnLoad(e);
}
public class TitleWebControl : Sitecore.Web.UI.WebControl
{
protected override void DoRender(HtmlTextWriter output)
{
var context = new SitecoreContext();
var model = context.GetCurrentItem<ISampleItem>();
output.Write(model.Title);
}
}
--You received this message because you are subscribed to the Google Groups "Glass.Sitecore.Mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glasssitecorema...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Value cannot be null. Parameter name: objectToSwitchTo
at Sitecore.Common.Switcher`2.Enter(TValue objectToSwitchTo)
at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in c:\clientWork\Glass.Mapper\Source\Glass.Mapper.Sc\GlassHtml.cs:line 546
I have traced this to the following code:
using (new ContextItemSwitcher(scClass))
{
RenderFieldArgs renderFieldArgs = new RenderFieldArgs();
renderFieldArgs.Item = scClass;
var scClass = config.ResolveItem(finalTarget, database);
private string MakeEditable<T>(Expression<Func<T, object>> field, Expression<Func<T, string>> standardOutput, T target, object parameters)
{
StringBuilder sb = new StringBuilder();
var writer = new StringWriter(sb);
var result = MakeEditable(field, standardOutput, target, parameters, _context, SitecoreContext.Database, writer);
result.Dispose();
writer.Flush();
writer.Close();
return sb.ToString();
}
private string MakeEditable<T>(Expression<Func<T, object>> field, Expression<Func<T, string>> standardOutput, T target, object parameters)
{
StringBuilder sb = new StringBuilder();
var writer = new StringWriter(sb);
var result = MakeEditable(field, standardOutput, target, parameters, _context, SitecoreContext.Database, writer);
result.Dispose();
writer.Flush();
writer.Close();
return sb.ToString();
}