umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
Other
4.49k stars 2.69k forks source link

NetCore (alpha4): Problem with models builder and nested content #10073

Closed AndyButland closed 3 years ago

AndyButland commented 3 years ago

I found a problem using a nested content data type related to model builder (using V9 alpha 4).

To replicate:

Under Settings > Models Builder I see "Last generation failed with the following error":

Failed to build PureLive models.
Roslyn compiler could not create ModelsBuilder dll:
The type or namespace name 'NestedItem' could not be found in the global namespace (are you missing an assembly reference?)
The type or namespace name 'NestedItem' could not be found in the global namespace (are you missing an assembly reference?)

at Umbraco.Cms.Infrastructure.ModelsBuilder.RoslynCompiler.CompileToFile(String pathToSourceFile, String savePath)
at Umbraco.Cms.Web.Common.ModelsBuilder.PureLiveModelFactory.GetModelsAssembly(Boolean forceRebuild)
at Umbraco.Cms.Web.Common.ModelsBuilder.PureLiveModelFactory.EnsureModels()

Looking at the generated code, I can see the nested content property on "Home" is reference like this:

public global::System.Collections.Generic.IEnumerable<global::NestedItem> NestedItems ...

If I remove that global:: prefix, it compiles OK.

bergmania commented 3 years ago

Thanks for reporting.. I'm not sure why it needs to have the global::. Maybe we should just remove it...

elit0451 commented 3 years ago

I don't think it is related to the global:: prefix - that is the way we have it in v8 and there it works. I've also compared the auto-generated code with segments from the files generated through AppData mode and they are identical, so it is something else, not related to the generated code 🤔

Will continue investigating

P.S. No errors from generating the models with AppData mode.

chris-evansnz commented 3 years ago

@elit0451 in regards to AppData mode; how do we properly enable this using v9 alpha 004?

We have the following in our appsettings.json file:

"ModelsBuilder": {
      "ModelsMode": "AppData",
      "Enable": true
    }

But despite this, the backoffice still claims to be in PureLive mode, and we can't see any .cs files turn up for our doctypes.

image

AndyButland commented 3 years ago

Hi @chris-evansnz - I noticed this was already reported as an issue with alpha 4. There's a workaround suggestion and the possibility of upgrading to a nightly discussed here.