Copied to clipboard

Flag this post as spam?

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


  • bh 408 posts 1395 karma points
    Mar 12, 2019 @ 12:57
    bh
    0

    DocType Does Not Exist in PublishedModels

    In VS2017 i'm getting the error

    The type or namespace named 'NextUp' does not exist in the namespace 'Umbraco.Web.PublishedModels' (are you missing an assembly reference?)

    relevant code

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.NextUp>
    @using ContentModels = Umbraco.Web.PublishedModels;
    

    This is the case on all of my strongly typed views. What do I need to do to correct this?

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 12, 2019 @ 13:37
    Nik
    2

    Hi bh,

    What models builder mode are you using?

    At a guess you are probably getting the "error" as a false positive because you are using PureLive or DLL model for models builder (PureLive is the default). The error shows because the models don't exist untill run time and so VS thinks you are referencing things that don't exist (which is technically correct as at this point they dont), as a result you also can't get an intellisense .

    Nik

  • bh 408 posts 1395 karma points
    Mar 12, 2019 @ 13:44
    bh
    0

    Thanks @Nik

    Makes sense what you're saying. Yea the intellisense is the part i was wondering about. So the Models don't exist til runtime huh?

    I don't know the answer to your question about the PureLive or DLL. I haven't being using models builder on my other umbraco 7 projects (I don't think). When I spun up the new template in umbraco 8 it defaulted to this strongly typed PublishedModels.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 12, 2019 @ 14:08
    Nik
    101

    No problem :-)

    If you are spinning up a clean site then you are most likely using PureLive. You can check this by looking in the AppSettings in WebConfig. There should be a key called Models Builder Mode (or something similar) and it will probably read PureLive.

    The template is strongly typed, which is the good thing, as I say, it's just the VS behaviour that makes you question it :-)

    There are other modes, and I do recommend reading up on them to figure out what mode will work best for you. PureLive and DLL allow models to be created on the fly (runtime), where as the others generally lead you to creating them at compile time :-)

    Nik

  • bh 408 posts 1395 karma points
    Mar 12, 2019 @ 14:23
    bh
    0

    Thanks again @Nik.

    Yup. PureLive according to web.config

    So without intellisense what's the benefit of ModelsBuilder? Just that I can use @Model.attributeName instead of @Model.GetPropertyValue("attributeName")?

    I read up on Models Builder. I was sadly behind. I think I'd like to give DLL a go. I've "created" some DocTypes. Do you know if switch from PureLive to DLL in web.config if changes to those DocTypes will be picked up, or do I need to start over on those DocTypes?

  • Michael Nielsen 153 posts 810 karma points
    Mar 12, 2019 @ 14:35
    Michael Nielsen
    1

    Hi bh

    Just switch to DLL, and go to into the backend and build the Models (Developer section on v7's, Settings on v8's), then you can use Intellisense.

    It won't affect what you have created sofar.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 12, 2019 @ 14:36
    Nik
    0

    The advantage of Models builder is strongly typed models, and more so it's become a much better advantage now we have PropertyValueConverters as well.

    So, for example, you can do @Model.BannerImage.Url (although this is bad code for a different reason as BannerImage could be null even if you checked it had a value due to how the PropertyValueConverters work).

    Also, with Models builder models you can still do .GetPropertyValue because they all expose IPublishedContent which that extension method words off of.

    Strongly typed models, make your code, in theory, more readable which is nicer from a maintenance point of view.

    When you switch to Dll mode, in the back office you can go to the Models Builder dashboard in the developers section and tell your back office to regenerate the Dll. This will pick up changes you've made to doc types so you don't have to start over with any doc type changes :-)

    Dll mode will generate a dll in your bin directory called Umbraco.Web.PublishedModels which contains all of your compiled models.

    Now, I think you might still get the Intelli-sense issue you are currently getting unless you explicitly reference the dll in your project, but the issue you may get with this is that if you don't have that dll (for example if you do a clean of your solution) you may end up unable to run your project depending on if you have to reference Models in .cs files due to visual studio being unable to compile. Just as a warning :-)

    When you make the switch you "may" also get a temporary issue where 2 instances of models is found by the website but you can resolve this by doing a restart of the site I believe :-)

  • bh 408 posts 1395 karma points
    Mar 12, 2019 @ 14:40
    bh
    1

    greatttt... "Boot failed: Umbraco cannot run. See Umbraco's log file for more details." after switching to Dll I did the settings > Generate Models and mine didn't restart, so I stopped it in VS and tried to start again, and got this error. Sorry to bug ya'll but now i'm hosed.

  • bh 408 posts 1395 karma points
    Mar 12, 2019 @ 15:24
    bh
    0

    Switched back to PureLive and i'm up and running again.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 12, 2019 @ 15:27
    Nik
    0

    Did you get any errors in the log?

  • bh 408 posts 1395 karma points
    Mar 12, 2019 @ 15:38
    bh
    0

    yes to log file errors. I've tried a few different things trying to get back to good. Switching back to PureLive isn't copacetic either. Got the dual class reference error that @Nik mentioned. Now i'm back to Dll mode, but my project won't build says it's missing Model files that are there (but they show in VS with yellow triangle).

    Here's the log file: https://www.dropbox.com/s/0uuowj7ffqnzvaq/UmbracoTraceLog.HUDSONB-LT.20190312.json?dl=0

    Update: Excluded the missing models and got it to build in Dll mode. Generating models does not cause a restart automatically. I'm unsure how to proceed here.

  • DChad 5 posts 75 karma points
    Apr 22, 2020 @ 11:37
    DChad
    0

    @bh I have had the identical issues. Did you find a way of solving this?

  • bh 408 posts 1395 karma points
    Apr 22, 2020 @ 17:28
    bh
    1

    @DChad The how has changed since this post last March.

    In Visual Studio:

    1. Install the Umbraco.ModelsBuilder.API using Nuget Package Manager
    2. Tools > Options > Umbraco > fill out this form
    3. Add your models folder (I call mine ModelsLibrary) in the root of your website
    4. Add an Umbraco model (default is models1.mb) to your models folder
    5. Web.config appsettings should match below
    6. With your website running in debug mode right-click your models1.mb and choose "Build Models"

    If you get stuck there's documentation here: https://www.zpqrtbnk.net/posts/models-builder-extension/

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="" />
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true" />
    
Please Sign in or register to post replies

Write your reply to:

Draft