London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Weird IContentLoader error

Vote:
 

Hi,

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?

Thanks,

Mark

#151149
Jul 12, 2016 13:45
Vote:
 

Shared or local block on a page type?

#151150
Jul 12, 2016 14:59
Vote:
 

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.

#151151
Jul 12, 2016 15:07
Vote:
 

Hi

Isn't this a standard .NET message that can happen when you debug release built assemblies? Like mentioned here: http://stackoverflow.com/questions/8311303/cannot-obtain-value-of-local-or-argument-as-it-is-not-available-at-this-instruct

Regards

Per Gunsarfs

#151155
Jul 12, 2016 16:05
Vote:
 

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...

Mark

#151156
Jul 12, 2016 16:33
Vote:
 

Clear temporary files and rebuild?

#151158
Jul 12, 2016 17:15
Vote:
 

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...

#151159
Jul 12, 2016 17:20
Vote:
 

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

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

#151161
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.