The connection object can not be enlisted in transaction scope

Topics: Customizing Orchard, Troubleshooting, Writing modules
Sep 8, 2012 at 8:23 AM
Edited Sep 8, 2012 at 8:24 AM

Hi, I have a piece of code that stopped working when I loaded my project to another PC (source controlled). 

I created a module that has this piece of code:

public class TagShapeProvider : IShapeTableProvider
    {
        private readonly IWorkContextAccessor _workContextAccessor;
        private readonly ITagService _tagService;

        public TagShapeProvider(ITagService tagService, IWorkContextAccessor workContextAccessor) 
        {
          _workContextAccessor = workContextAccessor;
          _tagService = tagService;
        }
        
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("SiteSearch")
                .OnCreated(created =>
                    {
                        var tags = _tagService.GetTags();
                        created.Shape.PopularTags = tags;
                    });
        }

 

 The call to tagservice.GetTags()

 

public IEnumerable<TagRecord> GetTags() {
            return _tagRepository.Table.ToList();
        }

 

So nothing special really. This however throws two errors. On the call to the repo I get an ADO exception saying:

 

While preparing SELECT this_.Id as Id1005_0_, this_.TagName as TagName1005_0_ FROM Orchard_Tags_TagRecord this_ an error occurred

 

Followed by the error in the title on the following piece of code

if (shapeDescriptor != null) {
         foreach (var ev in shapeDescriptor.Created) {
             ev(createdContext);
    }
}

I'm using Orchard 1.5.1.0 by the way. 

 

thanks!

Sep 12, 2012 at 12:09 PM

Anybody, this is happening for all the IShapeTableProviders that access the database

Sep 12, 2012 at 12:28 PM

OK, this is caused by the fact that the injected objects are out of scope. If you create them using (for instance) var _contentManager = _workContextAccessor.GetContext(_httpContextAccessor.Current()).Resolve<IContentManager>(); it works

 

rinze