modelsbuilder / ModelsBuilder.Original

The Community Models Builder for Umbraco
MIT License
114 stars 49 forks source link

Can't Rebuild Models After Deleting Document Type #230

Closed RyanHelmn closed 5 years ago

RyanHelmn commented 5 years ago

Having a very strange issue with trying to generate models after deleting a document type from Umbraco.

I recently upgraded to Umbraco 8.3.0 using Models Builder 8.1.0. I haven't actually tried this on a fresh copy of Umbraco, so this could be a rare case....

If I create another document type, with the same alias, models generate fine, but once I delete it, it breaks again. Here's the error log:

Failed to build models. Don't know how to map ModelType with content type alias "imageGridItem".

at Umbraco.Core.Models.PublishedContent.ModelType.MapToName(Type type, Dictionary2 map, Boolean dictionaryIsInvariant) in D:\a\1\s\src\Umbraco.Core\Models\PublishedContent\ModelType.cs:line 103 at Umbraco.Core.Models.PublishedContent.ModelType.<>c__DisplayClass9_0.<MapToName>b__0(Type x) in D:\a\1\s\src\Umbraco.Core\Models\PublishedContent\ModelType.cs:line 119 at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Umbraco.Core.Models.PublishedContent.ModelType.MapToName(Type type, Dictionary2 map, Boolean dictionaryIsInvariant) in D:\a\1\s\src\Umbraco.Core\Models\PublishedContent\ModelType.cs:line 119 at Umbraco.ModelsBuilder.Building.TypeModel.MapModelTypes(IList1 typeModels, String ns) in D:\d\Zbu ModelsBuilder\src\Umbraco.ModelsBuilder\Building\TypeModel.cs:line 218 at Umbraco.ModelsBuilder.Building.Builder.Prepare() in D:\d\Zbu ModelsBuilder\src\Umbraco.ModelsBuilder\Building\Builder.cs:line 115 at Umbraco.ModelsBuilder.Building.Builder..ctor(IList1 typeModels, ParseResult parseResult, String modelsNamespace) in D:\d\Zbu ModelsBuilder\src\Umbraco.ModelsBuilder\Building\Builder.cs:line 99 at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.GenerateModels(UmbracoServices umbracoServices, String modelsDirectory, String bin, String modelsNamespace) in D:\d\Zbu ModelsBuilder\src\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 123 at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.BuildModels() in D:\d\Zbu ModelsBuilder\src\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 45

zpqrtbnk commented 5 years ago

Something, in your site, references the "imageGridItem" content type and a property value converter reports that the value of a property is of that type. Therefore, ModelsBuilder tried to map that "imageGridItem" alias to an actual generated type. But, if you have deleted the type with that alias, nothing is generated, and ... it fails.

Can you look into your content types for something (grid?) referencing "imageGridItem"?

RyanHelmn commented 5 years ago

I've given the project a search, aswell as a quick search in the database to see if the content type is still present even after deleting it, no where to be seen - I cleared out my generated models, rebuild my project to ensure the compiled dll hadn't persisted the value and nothing seems to want to work. project search

I'll try it out on a fresh install on 8.3.0 to see if it's a persisting issue and keep you posted!

RyanHelmn commented 5 years ago

Managed to get to the bottom of it, so I had the nested content item 'Image Grid Item' referenced in a nested content data type. I had gone back and removed the blank entry where the 'Image Grid Item' once was, and it's working again.

However, on the fresh Umbraco install, if I try and replicate this it doesn't seem to cause an issue.

I'll have a play around with it on the fresh Umbraco install and see if I can replicate it.

RyanHelmn commented 5 years ago

Unable to replicate in the fresh install, will close this ticket down. Seems that it's a very rare case that this would occur. Thanks!

zpqrtbnk commented 5 years ago

No worries, yes it might have been a glitch.

Sven883 commented 2 years ago

@zpqrtbnk we're having a similar issue. But there is no indiciation about which document type has been deleted. Any idea how we can find the deleted doc type? We're using umbraco modelsbuilder v8.1.6

UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: Exception: Response status code does not indicate success (InternalServerError)
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":"   at Umbraco.Core.Models.PublishedContent.ModelType.MapToName(Type type, Dictionary`2 map, Boolean dictionaryIsInvariant) in D:\\a\\1\\s\\src\\Umbraco.Core\\Models\\PublishedContent\\ModelType.cs:line 115\r\n   at Umbraco.ModelsBuilder.Building.TypeModel.MapModelTypes(IList`1 typeModels, String ns) in D:\\d\\Zbu ModelsBuilder\\src\\Umbraco.ModelsBuilder\\Building\\TypeModel.cs:line 218\r\n   at Umbraco.ModelsBuilder.Building.Builder.Prepare() in D:\\d\\Zbu ModelsBuilder\\src\\Umbraco.ModelsBuilder\\Building\\Builder.cs:line 115\r\n   at Umbraco.ModelsBuilder.Api.ApiHelper.GetModels(UmbracoServices umbracoServices, String modelsNamespace, IDictionary`2 files) in D:\\d\\Zbu ModelsBuilder\\src\\Umbraco.ModelsBuilder\\Api\\ApiHelper.cs:line 13\r\n   at Umbraco.ModelsBuilder.Api.ModelsBuilderApiController.GetModels(GetModelsData data) in D:\\d\\Zbu ModelsBuilder\\src\\Umbraco.ModelsBuilder.Api\\ModelsBuilderApiController.cs:line 87\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"}
UmbracoModelsBuilder:    at Umbraco.ModelsBuilder.Api.ApiClient.EnsureSuccess(HttpResponseMessage result)
   at Umbraco.ModelsBuilder.Api.ApiClient.GetModels(Dictionary`2 ourFiles, String modelsNamespace)
   at Umbraco.ModelsBuilder.CustomTool.CustomTool.UmbracoModelsBuilder.GenerateRaw(String wszInputFilePath, String wszDefaultNamespace, IntPtr[] rgbOutputFileContents, UInt32& pcbOutput, String& errMsg)