This project is read-only.

ValueFactory attempted to access the Value property of this instance

Topics: Customizing Orchard, Writing modules
Oct 22, 2012 at 4:32 PM
Edited Oct 22, 2012 at 6:00 PM

Hi Folks,

I'm getting a weird problem with one of my classes


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Cool.Services.Banking.Services;
using Orchard;
using Orchard.ContentManagement;

namespace Cool.Orchard.Banking.Models
    public class OrchardBankingServiceSettings : IBankingServiceSettings
        private readonly IContentManager _contentManager;
        private readonly BankingServiceSettingsPart _settings;

        public OrchardBankingServiceSettings(IContentManager contentManager)
            _contentManager = contentManager;
            _settings = _contentManager.List<BankingServiceSettingsPart>("CoolBankingSettingsType").FirstOrDefault();
            if (_settings == null)
                throw new NullReferenceException("Could not find the required item of content type: CoolBankingSettingsType");

        public string CashWalletName
            get { return _settings.CashWalletName; }

        public string HostUrl
            get { return _settings.ServiceUrl; }

        public string PointsWalletName
            get { return _settings.PointsWalletName; }


The class is registered with autofac using the following code in the module:


    public class AutoFacRegistration : Module
        protected override void Load(ContainerBuilder builder)


            //Add decorated banking service
               (p, c) => p.ParameterType == typeof(IBankingService),
               (p, c) => c.ResolveNamed<IBankingService>("bankingservice_implementor"));



I get the following error when executing the 2nd line of the constructor


{"ValueFactory attempted to access the Value property of this instance."}



   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Orchard.ContentManagement.DefaultContentManager.get_Handlers() in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 62
   at Orchard.ContentManagement.DefaultContentManager.New(String contentType) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 83
   at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 199
   at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 111
   at Orchard.ContentManagement.DefaultContentQuery.<Slice>b__0(ContentItemVersionRecord x) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 148
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Orchard.Utility.Extensions.ReadOnlyCollectionExtensions.ToReadOnlyCollection[T](IEnumerable`1 enumerable) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\Utility\Extensions\ReadOnlyCollectionExtensions.cs:line 8
   at Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 146
   at Orchard.ContentManagement.DefaultContentQuery.ContentQuery`1.Orchard.ContentManagement.IContentQuery<T>.List() in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 191
   at Orchard.ContentManagement.ContentQueryExtensions.List[T](IContentManager manager, String[] contentTypeNames) in d:\workspaces\BedeCloudTFS\DefaultCollection\BedeGaming\Bede.GRMS.Orchard\src\Orchard\ContentManagement\ContentExtensions.cs:line 129
   at Bede.GRMS.Orchard.Banking.Models.OrchardBankingServiceSettings..ctor(IContentManager contentManager)


I'm having trouble tracking down the reason why this error is occurring, and what I can do about it (other than it is something to do with the default content manager and Lazy objects). Using a different class to implement the interface (that does not use IContentManager) works just fine.

Can anyone identify this error, or maybe some advice on where to start looking?



Oct 22, 2012 at 5:32 PM

Why are you registering it manually, whereas you already have the IDependency that will do it for you?

Oct 22, 2012 at 6:00 PM

sorry - bad copying of code - I tried using IDependency to see if that made a difference (which it did not). I removed the IDependency interface from the implementation.

Oct 22, 2012 at 6:15 PM

Sooo, why not just use IDependency without the registration code? What doesn't work when you do that?

Oct 22, 2012 at 8:00 PM

beeeecause it gives me the error message listed above?

Oct 22, 2012 at 11:16 PM

So first things first, switch it back to IDependency...


"ValueFactory attempted to access the Value property of this instance

happens when you are accessign a Lazy Value.

So can you put IDependency on IBankingService, IBankingServiceSettings and IWebClientHelper.

Next can you debug and tell me the exact line it throws a wobbler on?

Oct 22, 2012 at 11:18 PM

No, I mean, what is the reason why you think you need to register manually (except for the cargo cult reason that you weren't able to make IDependency work)?

Oct 23, 2012 at 12:16 AM
Edited Oct 23, 2012 at 12:16 AM

Betrand: the reason was that the other implementations that have been used were not in Orchard dlls (I understand you don't do things like that around here). Cargo cult maybe a little strong? Honestly, use of Orchard is pretty cryptic, lacking in documentation, and I'm looking for help. I will attempt to debug further though the reason I'm asking the question is because I've got to the stack trace above and I don't have a clue what it is trying to tell me.


Jetski: I cannot put IDependency on those classes, they are not inside orchard dlls, but in library classes, but thanks for the constructive suggestion.

Oct 23, 2012 at 5:36 AM

OK, that's a perfectly fine answer. The code you posted was a little puzzling and misleading. Next step would be to attach a debugger and see what is using a Lazy<T> and failing.

Oct 24, 2012 at 5:15 PM

just a quick note - did not get to this today, but hopefully tomorrow!

Oct 24, 2012 at 9:03 PM

It maybe that the error inside of the handler is being masked by the LAzy<T>