Modelsbuilder - using umbraco types in custom code
I tried posting this question before but it has rendered unreadable so I try again.
I believe my problem originates from a lack of understanding how Modelsbuilder and strong types are to be used/configured. I'm new to Umbraco so the following is my best guess:
I've created DocumentTypeS (HeaderMenu and Footer) with a Template and corresponding Content and wish to use this type in backend custom code.
My basic layout for the site is (_Layout.cshtml which is Layout for content Home):
which I suspect is the reason for the following error when starting umbraco:
Boot failed: Umbraco cannot run. See Umbraco's log file for more details.
Umbraco.Core.Exceptions.BootFailedException: Boot failed.
System.InvalidOperationException: Unable to resolve type: Umbraco.Core.Composing.ComponentCollection, service name:
at LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError) in C:\projects\lightinject\src\LightInject\LightInject.cs:line 4748
at LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError) in
...
Where it, e.g., says the following in the log file:
Both types 'Umbraco.Web.PublishedModels.Footer, MyNameSpace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and
'Umbraco.Web.PublishedModels.Footer, Umbraco.Web.PublishedModels, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' want to be a model type for content type with alias \"footer\".\r\n
I've also experimentet with Dll mode but I get various errors depending on configuration settings and what I include where. No combination so far seems to give me what I want, which is basically strong types in the backend and a site that can boot!
Any help and suggestions will be much appreciated!
it looks like your site failes to boot because there are multiple models in your backend having different namespaces but have the same alias. I assume you created the models, changed the namespace and created it again.
Please try to delete unnecessary models and make sure Footer and HeaderMenu only exist once. After that, your site should boot properly.
Thank you very much for your reply. I did read the documentation but had a few things I didn't quite understood - go figure! :)
I suppose (?!) the mistake was to include the *generated.cs-files so I ended up starting over and went for the Dll mode. This seems to work, and due to the reference, I suppose, the types are now present only once.
Also, I ended up installing 8.1.0 (I'm on 8.0.2 right now), took a look at the example site, and reconfigured my templates. I now have a much simpler setup and have "strong" access to my types.
This is related ... but different. Apologies for the hijack.
I found this thread because I was searching for recent issues with the ModelsBuilder. Just started a new project, Umbraco Cloud and it looks like we're the unwitting guinea pigs with 8.1. Had real troubles generating models - breaking templates etc. Found the answer here:
TLDR: If you use API mode to build models to an external project - which is the recommended approach for cloud I believe - you should follow this guide - https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/ but use the new Extension (not custom tool) which has only been released on Friday.
It works, well done everybody for getting things fixed, but I spent a lot of time chasing around old misleading documentation - there has to be a better way of communicating breaking changes for such core things?
I also tried the custom tool solution and must have experienced the same problems you are hinting at. Thank you very much for pointing out the Extension!
Modelsbuilder - using umbraco types in custom code
I tried posting this question before but it has rendered unreadable so I try again.
I believe my problem originates from a lack of understanding how Modelsbuilder and strong types are to be used/configured. I'm new to Umbraco so the following is my best guess:
I've created DocumentTypeS (HeaderMenu and Footer) with a Template and corresponding Content and wish to use this type in backend custom code. My basic layout for the site is (_Layout.cshtml which is Layout for content Home):
In Web.config I set:
And in App_Data/Models/ I've included like so:
I know have the following in site.dk\App_Data\TEMP\TypesCache:
Umbraco.Web.PublishedModels.Footer, Umbraco.Web.PublishedModels, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Umbraco.Web.PublishedModels.HeaderMenu, Umbraco.Web.PublishedModels, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null ... Umbraco.Web.PublishedModels.Footer, MyNameSpace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Umbraco.Web.PublishedModels.HeaderMenu, MyNameSpace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
which I suspect is the reason for the following error when starting umbraco:
Umbraco.Core.Exceptions.BootFailedException: Boot failed. System.InvalidOperationException: Unable to resolve type: Umbraco.Core.Composing.ComponentCollection, service name: at LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError) in C:\projects\lightinject\src\LightInject\LightInject.cs:line 4748 at LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError) in ...
Where it, e.g., says the following in the log file:
I've also experimentet with Dll mode but I get various errors depending on configuration settings and what I include where. No combination so far seems to give me what I want, which is basically strong types in the backend and a site that can boot!
Any help and suggestions will be much appreciated!
Thank you!
Hi Martin,
it looks like your site failes to boot because there are multiple models in your backend having different namespaces but have the same alias. I assume you created the models, changed the namespace and created it again. Please try to delete unnecessary models and make sure Footer and HeaderMenu only exist once. After that, your site should boot properly.
If you wan't to know how to use strongly typed models in Umbraco, please take a look at the documentation: https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/ .
~ Jonathan
Hi Jonathan
Thank you very much for your reply. I did read the documentation but had a few things I didn't quite understood - go figure! :)
I suppose (?!) the mistake was to include the *generated.cs-files so I ended up starting over and went for the Dll mode. This seems to work, and due to the reference, I suppose, the types are now present only once.
Also, I ended up installing 8.1.0 (I'm on 8.0.2 right now), took a look at the example site, and reconfigured my templates. I now have a much simpler setup and have "strong" access to my types.
Thanks again!
Martin
This is related ... but different. Apologies for the hijack.
I found this thread because I was searching for recent issues with the ModelsBuilder. Just started a new project, Umbraco Cloud and it looks like we're the unwitting guinea pigs with 8.1. Had real troubles generating models - breaking templates etc. Found the answer here:
https://www.zpqrtbnk.net/posts/models-builder-extension/
TLDR: If you use API mode to build models to an external project - which is the recommended approach for cloud I believe - you should follow this guide - https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/ but use the new Extension (not custom tool) which has only been released on Friday.
It works, well done everybody for getting things fixed, but I spent a lot of time chasing around old misleading documentation - there has to be a better way of communicating breaking changes for such core things?
I also tried the custom tool solution and must have experienced the same problems you are hinting at. Thank you very much for pointing out the Extension!
is working on a reply...