Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carl Jackson 139 posts 478 karma points
    Feb 15, 2016 @ 10:53
    Carl Jackson
    0

    7.4 Models builder

    I've just installed Umbraco 7.4 and wanted to get started with the Models builder.

    I can't see any documentation on using or enabling, but on install I had issues with it not being enabled (missing web config key).

    I added in the "enabled" key and "EnableApi" key but now get the following message.

    ModelsBuilder is enabled, with the following configuration:

    • The models factory is enabled.
    • The API is enabled but not installed.
    • External tools such as Visual Studio cannot use the API.
    • No models mode is specified: models will not be generated.
    • Models namespace is Umbraco.Web.PublishedContentModels.
    • Static mixin getters are enabled.
    • The pattern for getters is "Get{0}".
    • Tracking of out-of-date models is not enabled.

    Any help appreciated! Thanks

  • Carl Jackson 139 posts 478 karma points
    Feb 15, 2016 @ 12:24
    Carl Jackson
    0

    ok I've added the following to my web config and can new "generate models"

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveAppData" />
    

    However it doesn't seem to do anythinig. no files are added to the Models folder.

    Do you need I need to install any other packages to make this work?

    Thanks

    Carl

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 10:05
    Stephen
    0

    Quick update: the Enable key is required to enable models at all; the EnableApi key is not required (it is for the API for Visual Studio which I don't think you need at the moment); the ModelsMode indicates how models are generated.

    With the LiveAppData models should be generated automatically in ~/App_Data/Models anytime you edit content types, however this "automatic" generation can fail, and because it all happens in the background, you will not see any error in the backend UI.

    Any chance you can look at Umbraco's log for some errors that would read:

    2016-02-17 10:59:39,314 [P6548/D14/T862] ERROR Umbraco.ModelsBuilder.Umbraco.LiveModelsProvider - Failed to generate models.
    

    ?

    Stephan

  • David Sheiles 69 posts 339 karma points
    Feb 15, 2016 @ 12:28
    David Sheiles
    0

    Hi Carl, I've just started trying it out myself and have had some success. If you update Umbraco.ModelsBuilder.ModelsMode to:

    <add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData" />
    

    it will add the generated.cs files to your App_Data/Models folder which you can either include in your project or physically move them to your models folder.

    Someone else might have a better method, but seems to have worked for me so far.

  • Carl Jackson 139 posts 478 karma points
    Feb 15, 2016 @ 12:55
    Carl Jackson
    0

    Hi David.

    I've tried that setting too but still don't get any models generated.

    Did you install any other nuget packages?

    Does your dashboard still state "The API is enabled but not installed." ?

    Thanks

    Carl

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 10:06
    Stephen
    0

    FWIW the "API" message is normal and if you don't know what it is... you don't need the API ;-) There's only 1 package that you need and it is the Umbraco.ModelsBuilder package.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 15, 2016 @ 13:05
    Jeroen Breuer
    1

    Hello,

    Maybe this posts helps: http://www.zpqrtbnk.net/posts/strongly-typed-models-news

    I don't think PureLive can be found anywhere. They just exist.

    You could also add this to the web.config:

    <add key="Umbraco.ModelsBuilder.EnableDllModels" value="true" />
    

    Than the models will be generated in Umbraco.Web.PublishedContentModels.dll in the bin folder.

    Jeroen

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 08:53
    Stephen
    1

    FYI Umbraco.ModelsBuilder.EnableDllModels is deprecated (not working anymore) and the "EnableXxx" are replaced by ModelsMode eg Umbraco.modelsBuilder.ModelsMode, value="Dll".

    I know.

    Currently writing doc.

  • David Sheiles 69 posts 339 karma points
    Feb 15, 2016 @ 13:14
    David Sheiles
    0

    Thanks Jeroen, Pure live models looks interesting.

    Carl, No havent installed anything but a fresh 7.4 through nuget and added the 3 keys to my web.config.

    Yes, my dashboard states The API is enabled but not installed.

    When I click the Generate models button, it adds the classes under ~/app_Data/Models/[doctypename].generated.cs

    Hope that helps

  • Carl Jackson 139 posts 478 karma points
    Feb 15, 2016 @ 13:18
    Carl Jackson
    102

    Found it.

    I had upgraded on an old dummy install which had a document type called "Grid" with a property named "Grid" obviously CSharp won't allow that naming in a class and so the model builder was throwing an error.

    Found it in the error log, however the Model builder dashboard was failing silently without even a JS console error.

    Thanks for your help, one to watch out for just in case I suppose!

    Thanks

    Carl

  • Jason 122 posts 658 karma points
    Feb 17, 2016 @ 19:30
    Jason
    1

    I also discovered that you cannot have document type named Properties. This will cause conflicts in the models and they will not compile.

  • Carl Jackson 139 posts 478 karma points
    Feb 17, 2016 @ 20:46
    Carl Jackson
    2

    Just wondering if a lot of these issues would be resolved if the model builder suffixed "Model" or "ViewModel" to the classes?

    It's a convention I would normally use anyway in a MVC environment.

    Their could also be a blacklist of property names which the model builder would check against like"Properties" and anything inherited from IPublishedContent which get suffixed with "Property".

    As a developer it all makes sense why we have these issues but a front ender / novice may struggle with errors like the ones we are seeing here.

    Thanks

  • Jason 122 posts 658 karma points
    Feb 17, 2016 @ 21:20
    Jason
    1

    I agree with what you are saying. Unfortunately, after spending two days trying to get this to work I had to give up. I was really looking forward to this feature but in my opinion it still needs a bit more refinement before it is ready for prime time.

  • Carl Jackson 139 posts 478 karma points
    Feb 17, 2016 @ 21:26
    Carl Jackson
    0

    I hear what you're saying, I think when we have instructions it shoukd make sense. It's worth it once you have it working though I can say that.

    With folders for doc types to keep compositions out if the way and the way compositions are setup as interfaces you can really setup a DRY structure to views and partial views!

  • Brian Powell 44 posts 199 karma points c-trib
    Feb 17, 2016 @ 23:27
    Brian Powell
    1

    It doesn't work if you have a document type named Content either.

  • Stephen 767 posts 2273 karma points c-trib
    Feb 18, 2016 @ 09:04
    Stephen
    0

    Indeed, because IPublishedContent already has a property named Content. Wondering if we should detect these collisions and suffix the properties with "something" to avoid the collision, eg generate ContentProperty instead of Content as proposed elsewhere in this thread.

    When Models Builder was not "automatic" & embedded in Umbraco, ppl would learn about these situations & take care of them. I can understand that it is confusing now that it is supposed to "just work".

  • Stephen 767 posts 2273 karma points c-trib
    Feb 18, 2016 @ 09:06
    Stephen
    0

    Indeed. Because IPublishedContent has a property named Properties and then there's a collision. Unfortunately these collisions are due to C# so the only solution is to make sure they do not happen.

    There are ways (that I need to document) to tell the Models Builder to generate the model with a different class name eg PropertiesModel in order to get rid of the collision.

    I am also wondering (see other posts in this thread) whether we should automatically detect them and add a suffix, eg PropertiesModel. But wouldn't that be confusing? How would you know that content type Foo is generated as "Foo" but Index is generated as "IndexModel"?

  • Carl Jackson 139 posts 478 karma points
    Feb 18, 2016 @ 09:10
    Carl Jackson
    0

    I would say we suffix "Model" to the class on every model. (adding a setting for backward compatibility)

    It would be just conflicting properties that would be detected and suffixed?

    Using intelisense its easy to see.... but understand taht isn't how everyone works.

  • Rob de Mercado 31 posts 147 karma points
    Feb 16, 2016 @ 09:00
    Rob de Mercado
    1

    Having spent some considerable time searching, I cannot find a single piece of complete documentation on the appSettings for Models Builder. All I find are disperate bits of advice (like on this page) on what to set certain the values keys to. Where is all this information documented???

    So, further to the original comment in this thread, is there ANYWHERE where a complete novice to ModelsBuilder can find comprehensive documentation on how to configure and use ModelsBuilder PLEASE!!!

    Also, there was no note on the 7.4 upgrade page saying that if manually upgrading, to copy the ModelsBuilder folder from the AppPlugins folder in the upgrade package into an existing site (although this was obvious it should have been mentioned).

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 08:54
    Stephen
    3

    is there ANYWHERE where a complete novice to ModelsBuilder can find comprehensive documentation

    I am currently putting together such a doc, to be released sometime this week. I know. I'm sorry.

    Stephan

  • David Sheiles 69 posts 339 karma points
    Feb 17, 2016 @ 10:06
    David Sheiles
    0

    Thanks Stephan,

    Really appreciate all the hard work you've put into Models Builder!

  • Tommy Enger 72 posts 277 karma points c-trib
    Feb 16, 2016 @ 09:17
    Tommy Enger
    0

    From the 7.4 blog post:

    "The following weeks will see many blog posts about all the awesome new features in Umbraco 7.4"

    This will hopefully include one or more post on how to use the models builder...

    If I understood correctly, it's just ZBU.ModelsBuilder that has been included in the core and renamed to Umbraco.ModelsBuilder. If that's the case, you might be able to use some of the documentation here

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 08:55
    Stephen
    1

    It is, unfortunately the doc is not up-to-date at the moment - in a few days.

  • Chris Lord 58 posts 211 karma points
    Feb 17, 2016 @ 14:24
    Chris Lord
    0

    I am trying to use ModelsBuilder on a 7.4.0 site upgraded from 7.3.7. It's enabled and mode set to AppData in the web.config, when i try and "Generate Models" from the developer section, nothing is created and no error logged in umbraco logs.

    When I click on the "save and generate model" on the doc type, i get a blue notification saying it may take a while, then immediately fails, again nothing specific to models logged in the log file.

    I tried on a fresh 7.4.0 site and seems to work ok, any idea what might be the issue on my upgraded site?

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 14:27
    Stephen
    1

    Can you confirm that you see no error in the log? Can you try with log4net priority set to "Debug" and see whether it makes a difference? Finally, can you enable "dev tools" in the browser (eg F12 in Chrome) and look at the response for the network request that fires when you click on "generate" in the devs section?

    Thanks

  • Chris Lord 58 posts 211 karma points
    Feb 17, 2016 @ 14:52
    Chris Lord
    0

    Ah thanks, found the issue, whilst I checked that none of my doc types had property names the same as the doc type name, I failed to realise there was a doc type called Image (i.e. the same as the Image media type), I didn't even think to check the network tab......time for a lie down!!

  • Stephen 767 posts 2273 karma points c-trib
    Feb 17, 2016 @ 14:55
    Stephen
    0

    Mmm... but there was no error in the log? Can you confirm? Then, that's bad and we need to fix!

  • Carl Jackson 139 posts 478 karma points
    Feb 17, 2016 @ 15:00
    Carl Jackson
    0

    This is the same as the issue I had, I did get a log error but I use Usync and it was getting pushed up the log by the usync event logs.

    As per Chris above though, there is no error message in the backend when generating models from the dashboard screen.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Feb 20, 2016 @ 17:01
  • Stephen 767 posts 2273 karma points c-trib
    Feb 21, 2016 @ 16:35
    Stephen
    0

    Documentation is currently work-in-progress but you may find the following page interesting https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Builder-Modes

  • Paul 89 posts 167 karma points
    Feb 20, 2016 @ 20:07
    Paul
    0

    Hi,

    I had to look at the Model builder and got a few errors, which I overcome by reading this blog post, but now I get the following error in the TraceLog.txt.

    This happens when I try to Save and generate models on the document type.

     2016-02-20 20:03:38,335 [P4888/D2/T16] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:44,700 [P4888/D2/T16] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:44,726 [P4888/D2/T30] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:54,921 [P4888/D2/T40] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:54,954 [P4888/D2/T46] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:56,019 [P4888/D2/T9] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:56,054 [P4888/D2/T40] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
    

    Any ideas on this one? I've resolved property fields with alias Image, Content.

    The Models Builder tab doesn't do anything in the Developer section. If I click Generate models there are no console errors or errors logged in the log file.

    Thanks,

    Paulius

  • Kenneth Solberg 227 posts 418 karma points
    Feb 20, 2016 @ 22:47
    Kenneth Solberg
    1

    For VS devs, simply:

    1. Set ModelsMode to AppData in web.config
    2. Go to the developers section and Models Builder tab and hit the genereate button
    3. Include the generated files in App_Data\Models to your project
    4. In your view inherit from UmbracoViewPage < GeneratedModel >

    5. Access strong typed members on Model.SomeProp

    Oila!

  • Phill 115 posts 289 karma points
    Feb 21, 2016 @ 02:17
    Phill
    0

    Hi Kenneth,

    Can you tell me how you're including App_Data\Models in your project? I have an Umbraco site and then 3 separate class libraries, Services, Controllers, Models. In VS I've set my Umbraco Site to be dependent on those other projects as they need to be built and included for my Umbraco site to work. So if I were to try and "include" something from my Umbraco site how would I do that without creating a circular reference issue?

    Do you possibly mean that you just "include" the code in the same Umbraco site project as it's excluded/hidden by default?

    I might be missing something simple, but I've never included just a folder from another project before, I always include the project/dll as a reference.

    Thanks in advance. Regards,

  • Carl Jackson 139 posts 478 karma points
    Feb 21, 2016 @ 12:03
    Carl Jackson
    0

    It may be better for you to use "DLL" models mode and then reference the generated library in all the projects that need it. That will get around your circular dependency.

  • Stephen 767 posts 2273 karma points c-trib
    Feb 21, 2016 @ 16:40
    Stephen
    0

    That probably is the easiest solution if you are a VS dev and want to compile the models as part of your solution but don't want to deal with the VS extension.

  • Stephen 767 posts 2273 karma points c-trib
    Feb 21, 2016 @ 16:43
    Stephen
    0

    If you'd rather have the models in a class library, then maybe it's worth trying to use the Visual Studio extension that will enable you to generate the models straight into your class library.

    This is how I use the Models Builder BTW.

    You can find details on how to use the VS extension in the documentation wiki on the project's GitHub.

  • Phill 115 posts 289 karma points
    Feb 22, 2016 @ 02:37
    Phill
    0

    Hi Stephen,

    I've actually been using the VS Extension for my current class library and it works. However it was last update Sept 2015 and when I added to my solution it's using the v2 Zbu.ModelsBuilder dlls. Is there an easy way to update it so that it uses the new v2 ModelsBuilder? Nothing seems broken at the moment using v2 but I would prefer to use the version that's shipping with current version of Umbraco.

    EDIT: I just thought I'd take another look online at VS Extensions Gallery and noticed that on Feb 16 a new version of the Extension was published. That solves issue for me :) Thanks again!

    https://visualstudiogallery.msdn.microsoft.com/ef0896ab-e2eb-47fc-8fcb-79dad0f66e30

    Thanks, Phill

  • Josh Yates 6 posts 86 karma points
    Jul 09, 2016 @ 21:46
    Josh Yates
    0

    This fixed it. I didn't see the all.generated.cs file in the Models folder.

  • Jonas 123 posts 206 karma points
    Sep 15, 2016 @ 12:38
    Jonas
    0

    Just upgraded from 7.3.1 to latest and under the "Model Builder" Tab its empty :-(

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Feb 21, 2016 @ 13:02
    Paul Wright (suedeapple)
    1

    There maybe some confusion due to how people "open" their Umbraco site into Visual Studio.

    If you open it in VS as a "website" then:

    Use ModelsMode: Dll, or LiveDll (prefereably "LiveDll") as this will auto restart the app, and redploy the Dll when you make any changes to the DocumentType in the Backoffice. You don't want to use the "AppData" mode, as this would NOT get compiled at runtime.

    Dll mode will plonk a "dll" (hey!) into your bin folder automatically, and when you create a new View, you should be able to do this in VS:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.HomePage>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    
    
    @Model.Content.HelloWorld
    

    If you open your site as a "Web Application", then you can Use the "AppData" or "LiveAppdata" mode, and just include the auto generated files in "AppData/Models" into your project solution. (You do this by clicking right mouse button on the file, and selecting "include in project)

    Hope that clears things up! :D

  • Paul 89 posts 167 karma points
    Feb 21, 2016 @ 13:59
    Paul
    0

    Hi,

    I've tried everything is suggested on this topic, however I can't get Models Builder to work on my existing project.

    These are the errors I was getting:

     2016-02-20 20:03:54,921 [P4888/D2/T40] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:54,954 [P4888/D2/T46] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:56,019 [P4888/D2/T9] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-20 20:03:56,054 [P4888/D2/T40] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-21 13:35:44,524 [P14292/D2/T31] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field onlyImages
     2016-02-21 13:35:44,524 [P14292/D2/T31] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-21 13:36:21,628 [P14292/D2/T9] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-21 13:36:29,511 [P14292/D2/T7] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field onlyImages
     2016-02-21 13:36:29,511 [P14292/D2/T7] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field startNodeId
     2016-02-21 13:36:40,479 [P14292/D2/T9] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field editor
     2016-02-21 13:36:40,479 [P14292/D2/T9] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field hideLabel
     2016-02-21 13:39:14,516 [P14292/D2/T48] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field min
     2016-02-21 13:39:14,516 [P14292/D2/T48] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field step
     2016-02-21 13:39:14,516 [P14292/D2/T48] WARN  Umbraco.Web.Models.Mapping.PreValueDisplayResolver - Could not find persisted pre-value for field max
    

    I've got rid of them by going to Data types as add these values for Multiple Image Picker, Rich Text Editor, Numeric, however now I have no errors in the trace log file, but when I try to Save and Generate Models I get an error suggesting to look at U logs.

    Managed to get Models Builder to work on a fresh install with a starter kit from Umbraco installation.

    / Paulius

  • marcelh 171 posts 471 karma points
    Feb 23, 2016 @ 09:56
    marcelh
    2

    With regards to the naming of generated content models, may I suggest to suffix the generated models with "...ContentModel".

    For a while using the ModelsBuilder is my prefered way of working on Umbraco websites. When developing more complex solutions that also include "regular" MVC models (that interact with views and controllers), I often found myself having to rename my models appropriatley. After a while I started to move content models in a separate namespace and used the naming convention suffixed with "...ContentModel". This made my code not interfere with regular MVC models, or models that I use to map my Archetype's on. And it made my code easier to understand: ContentModels are a special kind that inherit from PublishedContentModel.

    Currently, this requires a RenameContentType but I'm happy to use that. Even better would be a configurable option (on the custom tool, or in the application's configuration), just as the namespace is configurable, that enables you to specify your suffix of choice.

    My models folder/namespace best practise:

    Models - contains all regular MVC XyzModels (e.g. ContactModel)
    Models\ArchetypeModels - contains all mapped XyzArchetypeModels (e.g. ContactArchetypeModel)
    Models\ContentModels - contains the ContentModelBuilder class and all XyzContentModels, and their partial extensions (e.g. ContactContentModel.generated and ContactContentModel partial class extensions)
    

    The ContentModelBuilder class contains the assembly tags for renaming or ignoring my content types:

    [assembly: RenameContentType("Contact", "ContactContentModel")]
    [assembly: IgnoreContentType("Whatever")]
    
  • Craig100 1136 posts 2523 karma points c-trib
    Mar 23, 2016 @ 19:01
    Craig100
    0

    Umb 7.4.2, fresh install. I'm trying for a second time to get this to work.

    I have the VS Extension installed, the Umbraco.ModelsBuilder.API installed, web.config :-

    <add key="Umbraco.ModelsBuilder.Enable" value="true"/>
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveDll"/>
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true"/>
    

    The top of my Home page template has:-

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.HomePage>
        @using ContentModels = Umbraco.Web.PublishedContentModels;
    

    There is an error indicated on the .HomePage so attempted to generate models in the dev section......

    The Dev section says:-

    ModelsBuilder is enabled, with the following configuration:
    The models factory is enabled.
    The API is installed and enabled.
    The API endpoint is open on this server.
    LiveDll models are enabled.
    Models namespace is Umbraco.Web.PublishedContentModels.
    Static mixin getters are enabled. The pattern for getters is "Get{0}".
    Tracking of out-of-date models is not enabled.
    Generating models will restart the application.
    

    When generated, I get the following errors:-

    Last generation failed with the following error:
    Failed to build models.
     'IPublishedContent' does not contain a definition for 'GetBodyText' and no extension method 'GetBodyText' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
    
     at Umbraco.ModelsBuilder.Building.Compiler.ThrowExceptionFromDiagnostic(IDictionary`2 files, Diagnostic diagnostic) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 154
     at Umbraco.ModelsBuilder.Building.Compiler.Compile(String assemblyName, IDictionary`2 files, Stream stream) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 131
     at Umbraco.ModelsBuilder.Building.Compiler.Compile(String assemblyName, IDictionary`2 files, String binPath) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 79
     at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.GenerateModels(String appData, String bin) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 126
     at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.BuildModels() in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 37
    

    I've tried the above with ModelsMode value = "Dll" as well, it makes no difference.

    I should point out the pages use docType compositions, if it makes a difference.

    Any advice would be appreciated.

  • Stephen 767 posts 2273 karma points c-trib
    Mar 24, 2016 @ 16:04
    Stephen
    0

    Several things:

    If you are using the Visual Studio extension and generating and compiling models in Visual Studio then you should set ModelsMode to Nothing as you do not want the site to generate models (it's done in Visual Studio).

    In other words: either you generate models in Visual Studio and include them in your solution, or you generate them in the site in the Dev section, but not both.

    Then, the "Failed to build models" error says that it cannot compiles the models that have been generated. Can you list the files in ~/App_Data/Models? Are you implementing partial model classes? Can you copy the content of models.generated.cs here?

  • Paul Gower 28 posts 74 karma points
    May 04, 2016 @ 19:22
    Paul Gower
    0

    How do you have your workflow setup for this to work, Stephen?

    I installed the VS2015 extension and set the options to point to the following:

    Umbraco Url: http://localhost:<-port-for-iis-express->
    Along with my username and password that is to a user that is a developer.

    What I am confused about is how to know if the extension is running or not. I assume it is not because the only way so far I've been able to get the models to generate in the ~/App_Data/Models/ folder like I want so I can include them in my project manually is to set the Mode to AppData and use the Umbraco Back office to generate the models.

    I am more than happy to help update the wiki or documentation to include the steps required to setup the generation piece to be manual and only from the local environment.

    Thanks!

  • Stephen 767 posts 2273 karma points c-trib
    May 09, 2016 @ 16:13
    Stephen
    0

    See "API Models " on https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Builder-Modes - basically, once the extension is installed and configured you need to create a specific folder + cs file in your solution. Let me know if the wiki/doc is not clear.

  • Paul Gower 28 posts 74 karma points
    May 11, 2016 @ 15:57
    Paul Gower
    0

    Thanks, Stephen, this clears it up for me!

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 24, 2016 @ 16:47
    Craig100
    0

    I just deleted contents of AppData/Models, set ModelsMode="Nothing", rebuilt, no models built, restarted site in Umbraco, no models built. So set ModelsMode="LiveDll" again and regenerated Models from the Dev section. As previously the AppData/Models directory was populated again with:- Admin.generated.cs

    BasePage.generated.cs

    Content.generated.cs

    File.generated.cs

    Folder.generated.cs

    HomePage.generated.cs

    Image.generated.cs

    Member.generated.cs

    models.err

    SEO.generated.cs

    Settings.generated.cs

    Content of models.err:-

    Failed to build models.
    'IPublishedContent' does not contain a definition for 'GetBodyText' and no extension method 'GetBodyText' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
    
       at Umbraco.ModelsBuilder.Building.Compiler.ThrowExceptionFromDiagnostic(IDictionary`2 files, Diagnostic diagnostic) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 154
       at Umbraco.ModelsBuilder.Building.Compiler.Compile(String assemblyName, IDictionary`2 files, Stream stream) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 131
       at Umbraco.ModelsBuilder.Building.Compiler.Compile(String assemblyName, IDictionary`2 files, String binPath) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 79
       at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.GenerateModels(String appData, String bin) in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 126
       at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.BuildModels() in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 35
    

    I don't understand why it's complaining about GetBodyText. It's certainly nothing I've added to a docType, unless it's something to do with the ModelsBuilder code?

    Apart from being extraordinarily difficult to set up to work with in VS, it seems an odd decision for Umbraco to make whereby on a vanilla install, if you generate a docType, you are forced to use the Models Builder unless you remove the auto-generated "inherit" and "using" and replace them with

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    The result is I have a BasePage.cshtml which has no dataTypes in it's docType and has no Model generated for it, so I'm not surprised it throws an error when using the auto-generated template in VS.

    I only want to use ModelsBuilder because: 1) It's the way Umbraco builds templates and 2) I understand it's supposed to be easier and simpler to type in CurrentPage.somename.

    But if it takes several days to set up then it's a false economy. I'd rather just replace the "inherit" and "using" and get on with it as normal. Just puzzled as to why it's the default set up in Umbraco now when it doesn't appear it can be used in VS simply.

  • Stephen 767 posts 2273 karma points c-trib
    Mar 24, 2016 @ 16:54
    Stephen
    0

    Well, point is, in most cases it "just works" ;-) Really sorry you are encountering these issues. I'm not sure I understand where the GetBodyText issue comes from, either, but willing to help. Could you zip the content of ~/App_Data/Models and email it to me, stephane at umbraco dot com?

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 24, 2016 @ 17:14
    Craig100
    0

    Thanks Stephen,

    Sent with Subject line: "Models Builder Issue 75079-74-models-builder"

  • Stephen 767 posts 2273 karma points c-trib
    Mar 24, 2016 @ 19:09
    Stephen
    2

    Replied by email. Interesting situation. Here is what happens:

    You have a content type named "Content". Which generates a class named "Content". It is also used in a composition, for content type "HomePage".

    That is, HomePage inherits property BodyText from Content. This is implementing by getting the value from a static getter on the Content class:

    ///<summary>
    /// Body Text: Main page content
    ///</summary>
    [ImplementPropertyType("bodyText")]
    public Newtonsoft.Json.Linq.JToken BodyText
    {
        get { return Content.GetBodyText(this); }
    }
    

    However, for some reason, Content is also a property of models, and it represents the inner IPublishedContent (the one you would get if you had no models). Here, the compiler fails to pick between your own Content class (which has a GetBodyText static method), and the Content property (which does not, obviously) so it fails to compile models.

    Workarounds:

    1. change the alias of the "Content" content type to eg "MyContent" - will work, but you might not want to do this, OR...

    2. keep the alias but change the class name, so although the alias would remain "content", the model would be of type "MyContent". This can be done by creating a MyContent.cs file in ~/App_Data/Models, containing the following code:

      using Umbraco.ModelsBuilder;
      [assembly: RenameContentType("content", "MyContent")]
      

    And rebuilding the models. You'll notice the Content.generated.cs files is deleted and replaced by a MyContent.generated.cs file.

    The long-term fix would be for the Models Builder to detect that situation and fully qualify the "Content" class name, eg

    get { return Umbraco.Web.PublishedContentModels.Content.GetBodyText(this); }
    

    Will probably do it in the next release, but cannot do it immediately.

    Alternatively, we should publish a list of "names to avoid" (eg "Content", "Index"...).

  • Craig100 1136 posts 2523 karma points c-trib
    Apr 16, 2016 @ 14:14
    Craig100
    0

    Please correct me if I'm wrong, but having got it working I'm finding it's of limited use. Most of my views are links to load partials where the main functions of the site are done. As far as I can see, the ModelsBuilder only applies to the view and as partials can't know what view they'll be called in, means you can't use it's syntax. I'm currently switching it off in all new sites.

    However, I'm all ears if there's another way (that doesn't involve jumping through too many hoops ;) ).

    Craig

  • Stephen 767 posts 2273 karma points c-trib
    Apr 18, 2016 @ 08:23
    Stephen
    0

    I'm with Carl on that one: if your Partial can be used in different views for different content types, say Content1 and Content2... then those content types probably have "something in common" that is rendered in the partial.

    Move that "something" to a new content type, say SomethingInCommon, and have Content1 and Content2 be composed of that new content type.

    The ModelsBuilder will generate an interface for the composition, ISomethingInCommon, that you can use in the Partial. Ie, the model type of View1 is Content1, the model type of View2 is Content2, and the model type of the partial is ISomethingInCommon.

    Making sense?

  • Carl Jackson 139 posts 478 karma points
    Apr 16, 2016 @ 16:59
    Carl Jackson
    0

    Depends how you structure your doc types, if you use compositions then models builder adds an interface for each composition

    You can then type your partial with an interface and by polymorphism each doc type with that composition can call the partial.

  • Craig100 1136 posts 2523 karma points c-trib
    Apr 16, 2016 @ 17:09
    Craig100
    0

    That's interesting. I might look at that, thanks.

  • Robert J. Bullock 386 posts 405 karma points
    May 02, 2016 @ 21:07
    Robert J. Bullock
    1

    Wow, what a mess this feature is... Thought I'd be producing a quick Umbraco site this afternoon but wound up going down the Models Builder rabbit hole! Really stupid decision to enable this by default with such poor documentation.

  • Carl Jackson 139 posts 478 karma points
    May 02, 2016 @ 21:45
    Carl Jackson
    0

    Hi Robert.

    I agree some official documentation is needed, but in general I don't think it's a 'mess'.

    What specific issues have you had?

    Carl

  • Stephen 767 posts 2273 karma points c-trib
    May 03, 2016 @ 06:03
    Stephen
    1

    Ah... there's been looong discussions about this. It's a tricky tool that should make it simpler for most yet can can make it more complex for others. But the experience should definitively not be that painful.

    And in theory having the Models Builder enabled by default should not prevent you from doing "a quick site" the way you used to. That is, you should be able to ignore it entirely.

    Do you think you could waste a little bit more time on it and list the top three pain points that you encountered? Actual points that is, ie not "missing documentation" but "I could not figure out how to do X" and "I wasted time understanding Y"? That would be very helpful.

    Thanks! Sorry about your experience.

    Stephan

  • Stephen 767 posts 2273 karma points c-trib
    May 03, 2016 @ 11:05
  • Robert J. Bullock 386 posts 405 karma points
    May 03, 2016 @ 16:33
    Robert J. Bullock
    0

    My issue with it is that it's enabled by default and the documentation is difficult to find. I had to mess with it a good two hours to figure it out. Ultimately my problem was that I had a docType composition named "Content" and that broke things apparently. However, renaming the docType did not solve the issue; I actually had to delete all of my document types and start from scratch. So, in addition to not expecting the Models Builder to be enabled by default, having to figure out how to configure it (and still have not figure out what the Visual Studio extension is or where I obtain it), I had this extra little bug in there that just made it very frustrating.

    Personally, I LOVE the idea of the Model Builder and will definitely use it, I just wish the Umbraco install itself had offered the option to enable it explicitly and perhaps some information about how to use it.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 02, 2016 @ 22:12
    Paul Wright (suedeapple)
    0

    Turn this feature off by default. Can't really see any real world legit use for it, and only saves you a few keystrokes.

    It just adds an extra layer of abstraction, and adds yet another way just to get to a bog standard property value.

  • Craig100 1136 posts 2523 karma points c-trib
    May 02, 2016 @ 22:24
    Craig100
    0

    @Paul, I'm inclined to agree.

  • Carl Jackson 139 posts 478 karma points
    May 03, 2016 @ 11:14
    Carl Jackson
    2

    Its a level of abstraction that is standard in MVC .net.

    The use of a ViewModel is a preferred approach to MVC, the model builder gives us the ability to add View models to a dynamic system which is a very useful feature.

    It also adds an additional layer of error checking to Views. You cant accidentally access a property by the wrong name or type it incorrectly, which is something which can easily sneak into production environments.

    In my opinion it should be the standard way of developing Umbraco sites going forward.

  • Tommy Enger 72 posts 277 karma points c-trib
    May 03, 2016 @ 11:37
    Tommy Enger
    1

    Have to agree with Carl on this one. Seems to me that the real problem here is that Umbraco is used by both senior programmers and hobby programmers (and everything in between). Senior programmers will love this level of abstraction, and like Carl points out, accessing properties by names(strings) will never feel right. For a hobby programmer this concept can be hard to grasp.

  • Craig100 1136 posts 2523 karma points c-trib
    May 03, 2016 @ 11:46
    Craig100
    0

    As a professional (not necessarily "senior" ;) ) web dev all I can say is .NET MVC has only been around a few years and not everyone is fully immersed in it outside of developing Umbraco sites.

  • Robert J. Bullock 386 posts 405 karma points
    May 03, 2016 @ 16:35
    Robert J. Bullock
    0

    I would agree that professional coders will like the Models Builder. It makes a lot of sense. I'm just hoping it is SOLID and doesn't come back to bite me in the future. For hobbyists (who the heck builds websites for a hobby?!), it would probably be frustrating and not necessary.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 03, 2016 @ 23:41
    Paul Wright (suedeapple)
    0

    Umbraco does return a model to the view, that's strongly typed :)

    Model.Content.Name etc

    It's just that the 'properties' that you require are accessed through a method accessed via the model which accepts a variable (property), which is used to obtain the actual data.

    It's obvious that if you create a property called 'content' it's going to clash with the standard model.content :)

  • Tommy Enger 72 posts 277 karma points c-trib
    Jun 14, 2016 @ 11:37
    Tommy Enger
    0

    How do I render the grid with the strongly typed model? I can see in the model that the propery is stored as a JToken.

    @Model.Content.MyGrid
    

    This just prints the JSON-object

  • Jay 425 posts 652 karma points
    Jun 28, 2016 @ 20:18
    Jay
    0

    Hi Stephen and everyone,

    I'm using Umbraco 7.4.3 and had been randomly getting YSOD saying

    Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    

    The stack trace shows the following error not sure why.

    Stack Trace:

    [FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
       Umbraco.ModelsBuilder.Umbraco.LiveModelsProvider.get_IsEnabled() in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\LiveModelsProvider.cs:27
       Umbraco.ModelsBuilder.Umbraco.LiveModelsProviderModule.Install() in C:\Users\Stéphane\Documents\Development\Umbraco\Zbu\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\LiveModelsProvider.cs:134
    
    [InvalidOperationException: The pre-application start initialization method Install on type Umbraco.ModelsBuilder.Umbraco.LiveModelsProviderModule threw an exception with the following error message: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
       System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +874
       System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +169
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +133
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734
    
    [HttpException (0x80004005): The pre-application start initialization method Install on type Umbraco.ModelsBuilder.Umbraco.LiveModelsProviderModule threw an exception with the following error message: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716
    

    Anyone got any idea? Can't figure out what triggered the error. It happens randomly.

    I've done a search around and someone mentioned to delete the package folder of Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0 and then restore the nuget package. That fixes the problem.

    But from time to time it happens again which is not that great.

    Thanks

  • Matt Taylor 873 posts 2086 karma points
    Dec 13, 2016 @ 16:17
    Matt Taylor
    0

    I've an Umbraco v7.2 project that's based on the Hybrid Framework for Umbraco v7 and that introduced me to the great thing that is the ModelsBuilder.

    So I've been using Zbu.ModelsBuilder v2.1.5 in Visual Studio mode for a while, before it was introduced the Umbraco core and I'd now like to upgrade my project to Umbraco v7.5 using nuGet.

    My question is what do I need to do/know in order to prevent any conflicts between the existing Zbu.ModelsBuilder package that is installed in my project and the version that will come with core?

    I'm thinking that if it's in the core now I'd like to use that rather than any unnecessary add-ons.

    Thanks, Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 13, 2016 @ 16:26
    Jeroen Breuer
    1

    I've upgraded a website to 7.5 and it's still using the old version of the ModelsBuilder. I didn't have any conflicts yet.

    However it's pretty easy to remove the old models builder and use the new version. You probably only need to update some namespaces after regenerating the models. I also did it for the 1-1 multilingual example: https://github.com/jbreuer/1-1-multilingual-example/commit/89cbd54f3d971c2e97c91125b4699beda0dcdfa5

    Jeroen

  • Matt Taylor 873 posts 2086 karma points
    Dec 15, 2016 @ 12:56
    Matt Taylor
    0

    Thanks Jeroen,

    I've performed the upgrade and like you say the original ModelsBuilder continued to work.

    I'm sure I saw some posts before about some people having trouble with it.

    Now I'll figure out how remove the original version and use the new one.

    Cheers, Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 15, 2016 @ 13:02
    Jeroen Breuer
    0

    Hi Matt,

    Glad to hear the upgrade went well. If you've installed the old version with NuGet you can use that to uninstall. I also did it in this commit: https://github.com/jbreuer/1-1-multilingual-example/commit/ac1399ca13c0c45fe2d12843e5646519371529e5

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft