-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetModelContentType throws ArgumentNullException #222
Comments
So To work around this issue, I've now surrounded the call with an injected string productsAlias = null;
using (umbracoContextFactory.EnsureUmbracoContext())
{
productsAlias = Project.GetModelPropertyType(p => p.Products).Alias;
} |
Retrieving the property alias doesn't require an It doesn't fix this issue, but at least allows you to retrieve the property alias in a generic/type safe way without all the overhead. |
It sure is bad to have to create a context to retrieve a property alias - see my answer on #223 - need to fix this. As for why a context is needed to retrieve a property type - at publisher's level, content types as well as documents are accessed through a snapshot which guarantees that they'll remain stable for the duration of the snapshot. For instance, if you retrieve a document 3 times in a row, you expect it to be the same all 3 times. Not to change, or worse, disappear. Same with content types. Things should be stable for the duration of a request, or, a snapshot. And the context creates and owns the snapshot. Reason why you need a context. Now I am wondering, for these metadata methods... we could wrap their code in a |
Thanks for the elaborate explanation @zpqrtbnk! Having a way to get the property alias without the context and throwing a descriptive exception when using this method without one looks like the best solution then 👍 |
While trying to get a property alias within Examines
TransformingIndexValues
event usingProject.GetModelPropertyType(p => p.Products).Alias
, I get anArgumentNullException
.Looking at the source, this method requires an
UmbracoContext
that's not available while this event is fired. Thefixme inject!
comment probably says enough:https://github.com/zpqrtbnk/Zbu.ModelsBuilder/blob/bf0da79aee8f52ec153bbb200131d1914ee95b2b/src/Umbraco.ModelsBuilder/Umbraco/PublishedModelUtility.cs#L27-L33
It should probably inject an
IUmbracoContextAccessor
somewhere and ensure the context exists, allow passing in a customIPublishedSnapshot
or at least returnnull
instead of throwing this exception.The text was updated successfully, but these errors were encountered: