Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Weird IContentLoader error



I have weird IContentLoader error and wondered if anyone can shed any light on what's causing it.

I have the code:

            var loader = ServiceLocator.Current.GetInstance();
            var contentBlock = loader.Get(Guid);

            if (contentBlock != null)
                var test = contentBlock.SomeProperty;

And the contentBlock is not null but when trying to access the property it throws a massive error.

When I check contentBlock in the immediate window I get the message "Cannot obtain value of local or argument 'contentBlock' as it is not available at this instruction pointer, possibly because it has been optimized away."

But if I do something like var contentBlock1 = loader.Get(Guid); in the immediate window then I get the block returned as expected.

Any thoughts on what's happening here?



Jul 12, 2016 13:45

Shared or local block on a page type?

Jul 12, 2016 14:59

At the moment it's happening when a shared block, I've not tested with a local block. The block in question is actually a FormContainerBlock inherited from the EPiServer so that I can add additional properties to the Form.

Jul 12, 2016 15:07


Isn't this a standard .NET message that can happen when you debug release built assemblies? Like mentioned here:


Per Gunsarfs

Jul 12, 2016 16:05

Hi Per,

I had seen that article and tried all the suggestions it contained and all my VS settings were and are as recommended. The issue is happening in a Bll component project so the code optimization scenario seems a valid cause. It was actually working yesterday and I thought it was caused by the naming of the variable but then it stopped working again today. Frustrating...


Jul 12, 2016 16:33

Clear temporary files and rebuild?

Jul 12, 2016 17:15

I've already tried that and it made no difference. It must be a VS debug issue, if I run the code without debugging it does not error. Makes it difficult if I need to debug though...

Jul 12, 2016 17:20

Yup. Add some logging with log4net if you need I guess :)

Sounds like you are running in release mode from the error...

Edited, Jul 12, 2016 17:53
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.