Field 'Library' not found on class 'Telerik.Site

Posted by Community Admin on 04-Aug-2018 09:53

Field 'Library' not found on class 'Telerik.Sitefinity.Libraries.Model.Document'.

All Replies

Posted by Community Admin on 07-Sep-2011 00:00

Hi,

The following line of code:

var documents = App.WorkWith().Documents().Publihed().Where(d => d.Library.UrlName == "foo").Get();

throws this exception:

Field 'Library' not found on class 'Telerik.Sitefinity.Libraries.Model.Document'.

A colleague of mine got the same exception, with a different object and/or property.

Posted by Community Admin on 12-Sep-2011 00:00

Hi Thomas,

I'm sorry to hear about the issues you are experiencing querying Documents. I have tested the sample you provided, but it's working fine locally, provided that I specify a valid UrlName (default-document-library in my case). Further, checking with our codebase, shows that objects of type Telerik.Sitefinity.Libraries.Model.Document do have a property Library declared (should be the same as using d.Parent) so there should be no problem using it as a filter in the lambda expression for filtering documents. Can you please share with us if there's anything else that you might consider helpful in letting us find out the reasons behind the problems you are experiencing? Thank you in advance!

Regards,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 13-Sep-2011 00:00

Hi Boyan,

"Telerik.Sitefinity.Libraries.Model.Document do have a property Library declared (should be the same as using d.Parent) so there should be no problem using it as a filter in the lambda expression for filtering documents."

Yes, of course. That's why my code actually compiles, but fails during execution.
I'm not sure what else I could tell you to help you debug this. My UrlName is also valid, for a specific (non-default) library. I just tried with the default library, and it's the same.

A colleague just told me he tried to do the same thing before, and that it didn't work for him either. So we both ended up going for a foreach loop instead.

Are you testing this from 4.2, or maybe from a more recent internal build? That's all I can think of.

Posted by Community Admin on 16-Sep-2011 00:00

Hi Thomas,

Thank you for getting back to me. Yes, I'm testing on our latest officially supported release (4.2 Hotfix 1) and also on the latest internal codebase, can you please try using Parent instead of Library and let me know if the issues persist. Also, is the problem project-specific, or it reproduces on a new project as well?

All the best,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 22-Sep-2011 00:00

Hi Boyan,

It actually works with Parent!
Tried again with Library, and it still doesn't work.

Is using Parent recommended / future proof? Is it guaranteed not to break with future Sitefinity versions?

I don't have the time to try with a new project, sorry. Maybe in a few weeks, if it's really useful to you.
On the other hand, I managed to get a slightly different exception (using the Library property), which may be useful to you:

InvalidOperationException
 
An exception occured during the execution of '
Extent<Telerik.Sitefinity.Libraries.Model.Document>().Where(secObj => ((((secObj.InheritsPermissions == True) AndAlso Not(secObj.Permissions.Any(p => (((((p.Deny % 2) != 0) AndAlso (p.ObjectId != secObj.Id)) AndAlso (p.SetName == value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass2`1[Telerik.Sitefinity.Libraries.Model.Document]).permissionSetName)) AndAlso value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass4`1[Telerik.Sitefinity.Libraries.Model.Document]).principalIDs.Contains(p.PrincipalId))))) AndAlso secObj.Permissions.Any(p => ((((p.Grant > 0) AndAlso (p.ObjectId != secObj.Id)) AndAlso (p.SetName == value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass2`1[Telerik.Sitefinity.Libraries.Model.Document]).permissionSetName)) AndAlso value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass4`1[Telerik.Sitefinity.Libraries.Model.Document]).principalIDs.Contains(p.PrincipalId)))) OrElse (((secObj.InheritsPermissions == False) AndAlso Not(secObj.Permissions.Any(p => (((((p.Deny % 2) != 0) AndAlso (p.ObjectId == secObj.Id)) AndAlso (p.SetName == value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass2`1[Telerik.Sitefinity.Libraries.Model.Document]).permissionSetName)) AndAlso value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass4`1[Telerik.Sitefinity.Libraries.Model.Document]).principalIDs.Contains(p.PrincipalId))))) AndAlso secObj.Permissions.Any(p => ((((p.Grant > 0) AndAlso (p.ObjectId == secObj.Id)) AndAlso (p.SetName == value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass2`1[Telerik.Sitefinity.Libraries.Model.Document]).permissionSetName)) AndAlso value(Telerik.Sitefinity.Data.Linq.SitefinityQuery+<>c__DisplayClass4`1[Telerik.Sitefinity.Libraries.Model.Document]).principalIDs.Contains(p.PrincipalId)))))).Distinct().Where(b => (b.ApplicationName == value(Telerik.Sitefinity.Modules.Libraries.Data.OpenAccessLibrariesProvider+<>c__DisplayClass16).appName)).Where(item => ((((item.Visible == True) AndAlso (Convert(Convert(Convert(Convert(Convert(item.Status))))) == 2)) AndAlso (item.PublicationDate <= DateTime.UtcNow)) AndAlso ((item.ExpirationDate == Convert(null)) OrElse (item.ExpirationDate > Convert(DateTime.UtcNow))))).Where(d => (d.Library.FieldValue("UrlName_") == value(ASP.widgets_filtersearch_main_ascx).LibraryUrlName))'. See InnerException for more details.


Thanks.

Posted by Community Admin on 22-Sep-2011 00:00

Hi Thomas,

That's a really peculiar behavior, I'm really curious if it will reproduce with an empty project on your side, please do not hesitate to let me know if you have had the time to test it. Generally, using Parent in the filter expression is safe, yes. Actually the Library property is a return of the parent, cast to DocumentLibrary type.  ((DocumentLibrary)this.Parent; )

Regards,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-Oct-2011 00:00

I have the same issue when executing this code:

var items = App.WorkWith().Documents().Where(
                x => x.Parent.Title == Library
                    && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live
                    && x.AvailableCultures.Contains(Thread.CurrentThread.CurrentCulture)).Get();

What could be the problem?

Regards,
Daniel

Posted by Community Admin on 24-Oct-2011 00:00

Hello Daniel,

The possible cause for the problems experienced is if you're using the "Library" property in a lambda expression. The reason for the problems is that the persisted field is Parent, while Library is a property that is internally retrieved as (<T>)this.Parent;  and when you're operating with an IQueryable  the Library property is not available unless you have made a ToList() call beforehand. What I'd recommend you as the correct approach is to use Parent. One more thing that's worth noting is that Parent.Title is an LString, so if you're passing the Library title in your query, you'd better cast it ToString().

All the best,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 24-Oct-2011 00:00

Hi Boyan,

Thanks for the explanation for this issue. But then, I'm confused why the sample I provided worked at all for you, as you said in your first reply. It shouldn't have, from what you just explained.

Posted by Community Admin on 27-Oct-2011 00:00

Hello Thomas,

Thank you for pointing this out, I'll need to research whether there might have been some internal ToList() call in the previous versions that could have made this possible, or whether I have not made that call unintentionally.

Regards,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed