Hi,
You'll need to add this to your registration:
ce.For<DataContext>().Use(() =>
new DataContext(BusinessFoundationConfigurationSection.Instance.Connection.Database));
Regards,
/Q
Hi thanks for the quick response, I made the proposed change, but still getting the same exception. Please see the code and exception below.
Updated Code:
private void InitializeServiceLocator() { var connString = ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString; var hostType = HostType.Installer; var container = new Container(); var context = new ServiceConfigurationContext(hostType, container); /* if (DynamicDataStoreFactory.Instance != null) { throw new Exception("DynamicDataStoreFactory.Instance is null, aborting initilization in BaseQuartzJob class"); }*/ new EventsInitialization().ConfigureContainer(context); new CommerceInitialization().ConfigureContainer(context); var factory = new SqlDatabaseFactory(); context.Container.Configure(ce => ce.For<IDatabaseHandler>().Use(factory.CreateDefaultHandler)); context.Container.Configure(delegate(ConfigurationExpression ce) { var locator = new StructureMapServiceLocator(context.Container); ce.For<IServiceLocator>().Use(locator); ce.For<DataContext>().Use(() => new DataContext(BusinessFoundationConfigurationSection.Instance.Connection.Database)); ce.For<IObjectInstanceCache>().Use<HttpRuntimeCache>(); ce.For<IRequiredMetaFieldCollection>().Singleton().Use<Mediachase.MetaDataPlus.NoRequiredMetaFields>(); ce.For<ISynchronizedObjectInstanceCache>().Use<RemoteCacheSynchronization>(); ce.For<ITypeScannerLookup>().HybridHttpOrThreadLocalScoped().Use<FakeTypeScannerLookup>(); ce.For<ICommerceContext>().HybridHttpOrThreadLocalScoped().Use<CommerceContextImpl>(); ce.For<ICurrentMarket>().Singleton().Use<CurrentMarketImpl>(); ce.For<IWarehouseRepository>().Singleton().Use<WarehouseRepositoryDatabase>(); ce.For<IWarehouseInventoryService>().Singleton().Use<CacheWarehouseInventoryService>() //.Ctor<IWarehouseInventoryService>().Is<WarehouseInventoryServiceDatabase>() .Ctor<IWarehouseInventoryService>().Is<Mediachase.Commerce.InventoryService.Compatibility.WarehouseInventoryProxy>() .Ctor<TimeSpan>().Is(new TimeSpan(1, 0, 0)); ce.For<IMarketService>().Singleton().Use<MarketServiceDatabase>(); ce.For<IPriceService>().Singleton().Use<PriceServiceDatabase>(); ce.For<IConvertUserKey>().Singleton().Use<ConvertGuidUserKey>().Named(typeof(Guid).Name); ce.For<IConvertUserKey>().Singleton().Use<ConvertSidUserKey>().Named(typeof(SecurityIdentifier).Name); ce.For<IConvertUserKey>().Singleton().Use<ConvertIntUserKey>().Named(typeof(int).Name); ce.For<IConvertUserKey>().Singleton().Use<ConvertBinaryUserKey>().Named(typeof(byte[]).Name); ce.For<MapUserKey>().Singleton().Use<MapUserKey>(); ce.For<ICatalogSystem>().Singleton().Use(() => CatalogContext.Current); ce.For<IPriceDetailService>().Singleton().Use<PriceDetailDatabase>(); ce.For<IChangeNotificationManager>().Singleton().Use<ChangeNotificationManager>(); }); ServiceLocator.SetLocator(context.Container.GetInstance<IServiceLocator>()); DataInitialization.InitializeFromCode(context.Container, factory, null); DynamicDataStoreFactory.Instance = new EPiServerDynamicDataStoreFactory(); //set defaults if (DataContext.Current == null) DataContext.Current = new DataContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString); MetaDataContext.DefaultCurrent = new MetaDataContext(connString); //CatalogContext.MetaDataContext = MetaDataContext.DefaultCurrent; }
New Exception:
2015-06-25 08:55:06,206 [ServerScheduler_QuartzSchedulerThread] ERROR Quartz.Core.ErrorLogger - An error occured instantiating job to be executed. job= 'marketplace.RebuildIndexJob'
Quartz.SchedulerException: Problem instantiating class 'TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type ScriptExecutor, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code: 202
No Default Instance defined for PluginFamily EPiServer.Data.SchemaUpdates.ScriptExecutor, EPiServer.Data, Version=8.8.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
at StructureMap.BuildSession.<.ctor>b__0(Type t) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 33
at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Util\Cache.cs:line 83
at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at EPiServer.Data.DataInitialization.InitializeFromCode(IContainer container, IDatabaseFactory dbHandlerFactory, CacheProvider cacheProvider)
at TelefloraQuartzJobs.Jobs.BaseQuartzJob.InitializeServiceLocator() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 112
at TelefloraQuartzJobs.Jobs.BaseQuartzJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 46
at TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\Common\RebuildSearchIndexJob.cs:line 37
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Quartz.Util.ObjectUtils.InstantiateType[T](Type type)
at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
--- End of inner exception stack trace ---
at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
at Quartz.Simpl.PropertySettingJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
at Quartz.Core.JobRunShell.Initialize(QuartzScheduler sched) [See nested exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type ScriptExecutor, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code: 202
No Default Instance defined for PluginFamily EPiServer.Data.SchemaUpdates.ScriptExecutor, EPiServer.Data, Version=8.8.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
at StructureMap.BuildSession.<.ctor>b__0(Type t) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 33
at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Util\Cache.cs:line 83
at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at EPiServer.Data.DataInitialization.InitializeFromCode(IContainer container, IDatabaseFactory dbHandlerFactory, CacheProvider cacheProvider)
at TelefloraQuartzJobs.Jobs.BaseQuartzJob.InitializeServiceLocator() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 112
at TelefloraQuartzJobs.Jobs.BaseQuartzJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 46
at TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\Common\RebuildSearchIndexJob.cs:line 37
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Quartz.Util.ObjectUtils.InstantiateType[T](Type type)
at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)]
Please note that "at TelefloraQuartzJobs.Jobs.BaseQuartzJob.InitializeServiceLocator() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 112" is numbered as Line # 60 in the code snippet here.
I think you'll need to create a dumb implementation of EPiServer.Data.SchemaUpdates.ScriptExecutor and register it for ScriptExecutor. This class is used to update sql files but you don't need it in your scheduled job.
/Q
I added a fake type and registered it using the statement below. But now the weird thing is that quartz does not spawn any jobs and it does not write anything to the logs either, looks like it is failing during initilization. Here are the changes I made.
Registry:
ce.For<EPiServer.Data.SchemaUpdates.ScriptExecutor>().Use<FakeScriptExecutor>();
Fake Class:
public class FakeScriptExecutor : EPiServer.Data.SchemaUpdates.ScriptExecutor { public override void ExecuteEmbeddedZippedScripts(string str1, System.Reflection.Assembly assembly, string str2) { return; } public override void ExecuteScript(string str, System.IO.Stream stream) { return; } }
Yes Qurtz has TopShelf and it was spawning the job on the given time before we added fake registry. But now it does not spawn the job at all.
Please see the schedule file I am using for testing.
<?xml version="1.0" encoding="UTF-8"?> <job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"> <processing-directives> <overwrite-existing-data>true</overwrite-existing-data> </processing-directives> <schedule> <job> <name>RebuildIndexJob</name> <group>marketplace</group> <description> This job creates runs every 15 minute incremental builds and at 2AM for full rebuild cache and index. Since it is IStateFul Job only on can execute at a time so in an incremental will wait to run until the rebuild finishes </description> <job-type>TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob, TelefloraQuartzJobs</job-type> <durable>true</durable> <recover>false</recover> </job> <trigger> <cron> <name>FullIndexJobTrigger</name> <group>all</group> <description>This job is for full cache and search rebuild at a given time</description> <job-name>RebuildIndexJob</job-name> <job-group>marketplace</job-group> <cron-expression>0 35 13 * * ?</cron-expression> </cron> </trigger> </schedule> </job-scheduling-data>
We were not seeing logs due to a logging issue, after resolving that, it turns out that we need an updated lincese for Quartz. But the strange things is that our licenses are working fine with website and commerce manager after upgarding to 8.x.
Thank you so much for all the help.
Hi,
I am getting another initalization issue (below), any pointers? Actually I tried but could not find the object that implements IFeatureSwitch.
2015-07-02 13:15:01,734 [_Worker-5] ERROR TelefloraQuartzJobs.Jobs.LawsonOrdersTransfer.KeepsakeOrdersTransferJob - Keepsake & TF Printed Material order transfer abnormally terminated EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type IFeatureSwitch, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code: 202 No Default Instance defined for PluginFamily Mediachase.Commerce.Core.Features.IFeatureSwitch, Mediachase.Commerce, Version=8.13.2.721, Culture=neutral, PublicKeyToken=6e58b501b34abce3 at StructureMap.BuildSession.<.ctor>b__0(Type t) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 33 at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Util\Cache.cs:line 83 at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215 at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) --- End of inner exception stack trace --- at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]() at EPiServer.ServiceLocation.Injected`1.get_Service() at Mediachase.Commerce.Orders.OrderGroup.PopulateCollections(DataTableCollection tables, String filter) at Mediachase.Commerce.Orders.OrderGroup.PopulateCollection[T](ClassInfo classInfo, MetaStorageCollectionBase`1 collection, DataSet dataSet) at dxBase.Library.Orders.TfPurchaseOrder.GetAllVendorOrdersForLawsonTransfer(Boolean retrieveKeepsakes) in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\dxBase.Library\Orders\TfPurchaseOrder.cs:line 595 at dxBase.Library.Orders.TfOrderContext.GetAllVendorOrdersForLawsonTransfer(Boolean retrieveKeepsakes) in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\dxBase.Library\Orders\TfOrderContext.cs:line 538 at TelefloraQuartzJobs.Jobs.LawsonOrdersTransfer.KeepsakeOrdersTransferJob.ProcessApplication(String applicationName) in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\KeepsakeOrders\KeepsakeOrdersTransferJob.cs:line 103
If I am not using this featuer, is it possible to not use it to avoid the error for the time being?
I can add a fake implementation as well, but for that I need to find the object that implements IFeatureSwitch interface. Could you please guide me in that respect?
Thanks
Azhar
The default implemetation of IFeatureSwitch is Mediachase.Commerce.Core.Features.DefaultFeatureSwitch - but it should be enabled on structuremap by default.
I would suggest you to do an assembly scan - so any classes registered by ServiceConfiguration attribute will be automatically registered - before add your custom registration.
EDIT: you should add this to your app.config\configuration:
<episerver.framework>
<scanAssembly forceBinFolderScan="true" />
<appData basePath="appData" />
</episerver.framework>
Regards.
/Q
It is an internal class - as I mentioned above you should enable the assembly scan, then register your custom implementation later.
/Q
Assembly scanning caused a whole bunch of issues, but the following fake type registration fixed my issue.
public class FakeFeatureSwitch : Mediachase.Commerce.Core.Features.IFeatureSwitch { void IFeatureSwitch.AddFeature(IFeature feature) { return; } void IFeatureSwitch.DisableFeature(string feature) { return; } void IFeatureSwitch.EnableFeature(string feature) { return; } IList<IFeature> IFeatureSwitch.Features { get { return null; } } FeatureState IFeatureSwitch.GetFeatureState(string feature) { return FeatureState.Enabled; } void IFeatureSwitch.InitializeFeatures() { return; } }
Registration:
ce.For<IFeatureSwitch>().Use<FakeFeatureSwitch>();
Sorry for the delay. I don't have the exceptions handy. But I can try to recreate them and send over. But in nutshell, there were tons of exceptions while attempting to initialize so many types, I remember CommonLogging was one of the assemblies (please note quartz uses common.logging).
I am having issues with quartz type initialization after upgrading EpiServer 7.x to 8.x. Please see the initilization code and exception below.
Initialization Code:
Exception:
2015-06-24 14:52:00,286 [ServerScheduler_QuartzSchedulerThread] ERROR Quartz.Core.ErrorLogger - An error occured instantiating job to be executed. job= 'marketplace.RebuildIndexJob'
Quartz.SchedulerException: Problem instantiating class 'TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type DataContext, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Mediachase.BusinessFoundation.Data.DataContext, Mediachase.BusinessFoundation.Data, Version=8.13.2.721, Culture=neutral, PublicKeyToken=41d2e7a615ba286c
at StructureMap.BuildSession.<.ctor>b__0(Type t) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 33
at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Util\Cache.cs:line 83
at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at Mediachase.BusinessFoundation.Data.DataContext.get_Current()
at TelefloraQuartzJobs.Jobs.BaseQuartzJob.InitializeServiceLocator() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 226
at TelefloraQuartzJobs.Jobs.BaseQuartzJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 45
at TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\Common\RebuildSearchIndexJob.cs:line 37
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Quartz.Util.ObjectUtils.InstantiateType[T](Type type)
at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
--- End of inner exception stack trace ---
at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
at Quartz.Simpl.PropertySettingJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
at Quartz.Core.JobRunShell.Initialize(QuartzScheduler sched) [See nested exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type DataContext, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Mediachase.BusinessFoundation.Data.DataContext, Mediachase.BusinessFoundation.Data, Version=8.13.2.721, Culture=neutral, PublicKeyToken=41d2e7a615ba286c
at StructureMap.BuildSession.<.ctor>b__0(Type t) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 33
at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Util\Cache.cs:line 83
at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at Mediachase.BusinessFoundation.Data.DataContext.get_Current()
at TelefloraQuartzJobs.Jobs.BaseQuartzJob.InitializeServiceLocator() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 226
at TelefloraQuartzJobs.Jobs.BaseQuartzJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\BaseQuartzJob.cs:line 45
at TelefloraQuartzJobs.Jobs.Common.RebuildSearchIndexJob..ctor() in c:\SRC2013\TheMarket\TheMarket\DEV-Epi8\Main\TelefloraQuartzJobs\Jobs\Common\RebuildSearchIndexJob.cs:line 37
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Quartz.Util.ObjectUtils.InstantiateType[T](Type type)
at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler)]