YAFLogo

santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
I'm working to install YAF as a control within an existing application for a client. I have the latest source, and I also have YAF successfully running as a standalone page using the default.aspx. I'm attempting to run YAF as a control within my existing application. As it currently stands I have the page where I'm trying to place the control properly functioning when the YAF control isn't there. When I place the YAF control, I receive the following error.

System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

The error occurs when I attempt to reference this.Master from within the base page the page inherits from. As I said, this isn't an issue until I insert the reference to the YAF control. Also, the default.aspx is running in this same virtual directory without issue, so it seems everything is configured as it should be.

I've found some older references pointing to an issues with Autofac, but I feel this may be misleading.

Any ideas would be enormously appreciated. I'm hopeful YAF has some far reaching potential for my customer, but I need to get this proof of concept fully functional before we can jump in with both feet.

Thanks.

Sponsor
santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
I changed the order of my calls in an attempt to resolve the issue and am now receiving the same error as part of the YafContext.cs.

The error is occuring on line 294 of YAF.Core.Context.YafContext.cs

///

/// Provides access to the Service Locatorer

///

public IServiceLocator ServiceLocator

{

get

{

return this._contextLifetimeContainer.Resolve();

}

}

This is only when running as a control. I've made the suggested configuration changes to allow running as a control, so I'm at a bit of a loss. I saw the related post from 2 years ago (http://forum.yetanotherforum.net/yaf_postst13330_Error-after-installing-YAF.aspx#post50251), but it does not apply to my situation as I'm using the supplied AutoFac under 1.9.6.1.

santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
A bit more info on this error. Here's the stack trace.

==========================================

Stack Trace

==========================================

Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(registration As IComponentRegistration, parameters As IEnumerable`1) (unknown file): N 00407

Autofac.ResolutionExtensions.ResolveService(context As IComponentContext, service As Service, parameters As IEnumerable`1) (unknown file): N 00168

Autofac.ResolutionExtensions.Resolve(context As IComponentContext, parameters As IEnumerable`1) (unknown file): N 00117

YAF.Core.YafContext.get_ServiceLocator() YafContext.cs: line 0294, col 05, IL 0001

YAF.Forum.get_ServiceLocator() Forum.cs: line 0325, col 05, IL 0006

YAF.Types.Interfaces.IServiceLocatorExtensions.Get(haveLocator As IHaveServiceLocator) IServiceLocatorExtensions.cs: line 0124, col 07, IL 0013

YAF.Forum..ctor() Forum.cs: line 0152, col 04, IL 0015

ASP.index_aspx.__BuildControlforum() index.aspx: line 0006, col 13, IL 0006

ASP.index_aspx.__BuildControlMainContent(__ctrl As Control) index.aspx: line 0005, col 13, IL 0020

System.Web.UI.MasterPage.InstantiateInContentPlaceHolder(contentPlaceHolder As Control, template As ITemplate) (unknown file): N 00125

ASP.globalmasterpages_myproject_master.__BuildControlMainContentPlaceHolder() myproject.Master: line 0116, col 13, IL 0095

ASP.globalmasterpages_myproject_master.__BuildControlContainerInterior() myproject.Master: line 0114, col 13, IL 0099

ASP.globalmasterpages_myproject_master.__BuildControlInteriorContentPlaceHolder() myproject.Master: line 0113, col 17, IL 0123

ASP.globalmasterpages_myproject_master.__BuildControlfrmMain() myproject.Master: line 0070, col 13, IL 0189

ASP.globalmasterpages_myproject_master.__BuildControlhtmBody() myproject.Master: line 0069, col 13, IL 0050

ASP.globalmasterpages_myproject_master.__BuildControlTree(__ctrl As globalmasterpages_myproject_master) myproject.Master: line 0001, col 13, IL 0052

ASP.globalmasterpages_myproject_master.FrameworkInitialize() App_Web_myproject.master.f98ccfed.nte8iojv.0.cs: line 0000, col 00, IL 0028

System.Web.UI.MasterPage.CreateMaster(owner As TemplateControl, context As HttpContext, masterPageFile As VirtualPath, contentTemplateCollection As IDictionary) (unknown file): N 01333

System.Web.UI.Page.ApplyMasterPage() (unknown file): N 00075

System.Web.UI.Page.PerformPreInit() (unknown file): N 00209

System.Web.UI.Page.ProcessRequestMain(includeStagesBeforeAsyncPoint As Boolean, includeStagesAfterAsyncPoint As Boolean) (unknown file): N 01397

if I implement IHaveServiceLocator and IRequireStartupServices on the page where I'm trying to place the control I get the same error but slightly different trace. Following is the stack trace:

==========================================

Stack Trace

==========================================

Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(registration As IComponentRegistration, parameters As IEnumerable`1) (unknown file): N 00407

Autofac.ResolutionExtensions.ResolveService(context As IComponentContext, service As Service, parameters As IEnumerable`1) (unknown file): N 00168

YAF.Core.AutoFacServiceLocatorProvider.Get(serviceType As Type) AutoFacServiceLocatorProvider.cs: line 0160, col 07, IL 0019

YAF.Types.Interfaces.IServiceLocatorExtensions.Get(serviceLocator As IServiceLocator) IServiceLocatorExtensions.cs: line 0044, col 07, IL 0024

YAF.Types.Interfaces.IServiceLocatorExtensions.Get(haveLocator As IHaveServiceLocator) IServiceLocatorExtensions.cs: line 0124, col 07, IL 0019

YAF.Core.IHaveServiceLocatorExtensions.RunStartupServices(serviceLocator As IHaveServiceLocator) IHaveServiceLocatorExtensions.cs: line 0051, col 07, IL 0013

YAF.Core.Services.PageRequestLoadServices.RequestedPage_PreInit(sender As Object, e As EventArgs) PageRequestLoadServices.cs: line 0121, col 09, IL 0026

System.EventHandler.Invoke(sender As Object, e As EventArgs) (unknown file): N 00000

System.Web.UI.Page.PerformPreInit() (unknown file): N 00049

System.Web.UI.Page.ProcessRequestMain(includeStagesBeforeAsyncPoint As Boolean, includeStagesAfterAsyncPoint As Boolean) (unknown file): N 01397

johnk
  • johnk
  • 74.8% (Friendly)
  • YAF All-the-Time
santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
Johnk, this is what I have, yet I'm getting the error that I outlined above.
johnk
  • johnk
  • 74.8% (Friendly)
  • YAF All-the-Time
11 years ago
I think you are using version 1.9.6.1

I would recommend upgrading to 2.0.0 Beta 2 from codeplex. It has a lot of bug fixes, enhancements, etc. This beta version is very stable. Even this forum is running on version 2.0.0 Beta 1 version.

santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
Johnk, thanks. I'll give 2.0b a shot tonight.
santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
Well, I downloaded the latest 2.0.0 Beta 2 code and gave it a go but I'm getting the same error.

Full Error Information:

System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)

at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)

at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)

at YAF.Core.YafContext.get_ServiceLocator() in c:\inetpub\YAF.net\YAF.Core\Context\YafContext.cs:line 303

at YAF.Forum.get_ServiceLocator() in c:\inetpub\YAF.net\YetAnotherForum.NET\Classes\Forum.cs:line 326

at YAF.Types.Interfaces.IServiceLocatorExtensions.Get[TService](IHaveServiceLocator haveLocator) in c:\inetpub\YAF.net\YAF.Types\Interfaces\IServiceLocatorExtensions.cs:line 139

at YAF.Forum..ctor() in c:\inetpub\YAF.net\YetAnotherForum.NET\Classes\Forum.cs:line 153

at ASP.index_aspx.__BuildControlContent1(Control __ctrl)

at System.Web.UI.MasterPage.InstantiateInContentPlaceHolder(Control contentPlaceHolder, ITemplate template)

at ASP.myproject_master.__BuildControlMainContentPlaceHolder()

at ASP.myproject_master.__BuildControlBodyContainer()

at ASP.myproject_master.__BuildControlfrmMain()

at ASP.myproject_master.__BuildControlFluidDiv()

at ASP.myproject_master.__BuildControlhtmBody()

at ASP.myproject_master.__BuildControlHtmlParent()

at ASP.myproject_master.__BuildControlTree(myproject_master __ctrl)

at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection)

at System.Web.UI.Page.ApplyMasterPage()

at System.Web.UI.Page.PerformPreInit()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)ncPoint, Boolean includeStagesAfterAsyncPoint)

Here is what I've found.

Both my page and my Master inherit from classes that ultimately inherit Page and MasterPage respectively. When I remove these items and instead have my page inherit directly from Page and MasterPage, YAF appears to function. I add back in my reference to my base page and it fails again, so it must be something in my base page and Autofac that aren't getting along.

The base page does a large amount of work for me. We've had it fully functional for years and it's even running as the base page under an Umbraco install. Items occur at each and every lifecycle event, from preInit to overriding Render. User varification, presentation items, and just about everything else having to do with a page's display stems from this critical class. I'm going to have to keep digging tomorrow, but if anyone has any idea on what may be causing this Autofac conflict please let me know.

Thanks.

johnk
  • johnk
  • 74.8% (Friendly)
  • YAF All-the-Time
11 years ago
It does look like a code conflict. Maybe you can create a new masterpage just for forum and copy the layout, design etc to this new masterpage. This way there would not be code conflicts.

Not sure if that would help though. YAF devs may have a better idea.

santanaf
  • santanaf
  • 50.2% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
I was able to resolve my issue. Took me a bit to think about what could cause it, but I was able to implement a fix.

Part of our base page class allows us to change the Master Page that's being used in the pre_init of the page load. This way our pages can be coded for a single website, but the master can be changed based on whatever presentation requirements are necessary. Well, it seems this change to the Master Page in the code causes Autofac to either prematurely dispose of the item that had already been initialized, or attempt to initialized a nested item (as suggested by the error). At that point any attempt to reference the item throws the error.

In the mean time, I'll add a configuration item that will allow us to disabled this on-the-fly changing of the master page for YAF specific pages. Ideally, we could still implement this feature at a later time, but that will take far more digging. May be as simple as order of operations.