This is probably a limitation of my understanding of the inter-workings of Umbraco so it is going to sound a bit stupid and I am asking here as I am trying to break my dependency on just asking AI for everything and go back to old school questions and research.
I dug around as best as I could but did not see anything. I have a property “headline” on my “News Article” document type. I have marked this property as “Field is mandatory” under the “Validation” configuration of the property.
I am now writing a C# method against this document type to do some parsing. I go to assign the value of “headline” to a ViewModle’s property public required string Headline { get; set; } but Visual Studio is warning me that the document type’s proper is “not nullable aware” and I have a “possible null reference assignment”.
This is the code I am using to assing/process some of the aticle information into the ViewModel:
IReadOnlyList<NewsArticleSnippetVM> newsArticles = articles.Select(x => new NewsArticleSnippetVM
{
Headline = x.Headline,
AuthorBiographyPageUrl = "null",
AuthorName = "null",
HeadlineImageUrl = "null",
ArticleSnippet = CreateArticleSnippet(x.Article.ToString()),
ArticleUrl = x.Url()
}).ToList();
Please ignore the null value assignments for some properties, I just have not figure out how to do those assignments yet.
I personally would have though that if a property is marked as “mandatory” then it would not be nullable at the code level.