Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: NullReferenceException #160

Closed
pedroadaodev opened this issue Dec 3, 2017 · 9 comments

Comments

@pedroadaodev
Copy link

pedroadaodev commented Dec 3, 2017

UmbracoModelsBuilder: Starting v3.0.6.97 03/12/2017 20:20:46.
UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: NullReferenceException: Object reference not set to an instance of an object.
UmbracoModelsBuilder: at Umbraco.ModelsBuilder.CustomTool.VisualStudio.VisualStudioHelper.ClearExistingItems(ProjectItem sourceItem)
at Umbraco.ModelsBuilder.CustomTool.CustomTool.UmbracoModelsBuilder.GenerateRaw(String wszInputFilePath, String wszDefaultNamespace, IntPtr[] rgbOutputFileContents, UInt32& pcbOutput, String& errMsg)

My Web.config

key="Umbraco.ModelsBuilder.Enable" value="true"
key="Umbraco.ModelsBuilder.ModelsMode" value="Nothing"
key="Umbraco.ModelsBuilder.EnableApi" value="true"
key="Umbraco.ModelsBuilder.LanguageVersion" value="CSharp5"

It was working... changed something in a document Type and BOOOMMM.
The website is running and the credentials are valid.

Can you help me?

Best regards,
Pedro

@pedroadaodev
Copy link
Author

Ok, I've deleted the latest Document Type and run the tool again. New error:

UmbracoModelsBuilder: Starting v3.0.6.97 03/12/2017 20:39:01.
UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: Exception: Response status code does not indicate success (InternalServerError)
{"Message":"An error has occurred.","ExceptionMessage":"Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater.","ExceptionType":"Umbraco.ModelsBuilder.Building.CompilerException","StackTrace":" em Umbraco.ModelsBuilder.Building.Compiler.ThrowExceptionFromDiagnostic(String path, String code, Diagnostic diagnostic) em X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 161\r\n em Umbraco.ModelsBuilder.Building.Compiler.<>c__DisplayClass12_0.b__0(KeyValuePair2 x) em X:\\Projects\\Umbraco\\ModelsBuilder\\Zbu.ModelsBuilder\\Umbraco.ModelsBuilder\\Building\\Compiler.cs:line 50\r\n em System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\r\n em System.Linq.Buffer1..ctor(IEnumerable1 source)\r\n em System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)\r\n em Umbraco.ModelsBuilder.Building.Compiler.GetCompilation(String assemblyName, IDictionary2 files, SyntaxTree[]& trees) em X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\Compiler.cs:line 46\r\n em Umbraco.ModelsBuilder.Building.CodeParser.Parse(IDictionary2 files, IEnumerable1 references) em X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Building\CodeParser.cs:line 38\r\n em Umbraco.ModelsBuilder.Api.ApiHelper.GetModels(String modelsNamespace, IDictionary2 files) em X:\\Projects\\Umbraco\\ModelsBuilder\\Zbu.ModelsBuilder\\Umbraco.ModelsBuilder\\Api\\ApiHelper.cs:line 16\r\n em Umbraco.ModelsBuilder.Api.ModelsBuilderApiController.GetModels(GetModelsData data) em D:\\d\\Zbu ModelsBuilder\\Umbraco.ModelsBuilder.Api\\ModelsBuilderApiController.cs:line 65\r\n em lambda_method(Closure , Object , Object[] )\r\n em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary2 arguments, CancellationToken cancellationToken)\r\n--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida ---\r\n em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n em System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida ---\r\n em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n em System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida ---\r\n em System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida ---\r\n em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n em System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida ---\r\n em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n em System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- Fim do rastreio da pilha da localização anterior em que a excepção foi emitida ---\r\n em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n em System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.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)

@pedroadaodev
Copy link
Author

Another strange thing.
I've created a new folder "temp1" and created an empty class aaaa.cs. Generated Model with success.

My old ModelsBuilder class still has the same error. :(

@pedroadaodev
Copy link
Author

Could it be another file that I have with the same name?

@pedroadaodev
Copy link
Author

Hey,

Just fixed this. Don know any it was broke. :(

What I did:
Moved all my Umbraco Models Builder PARTIALS to another folder.
My empty class for Umbraco Models Builder is in another folder alone.

Thanks,
Pedro

@hfloyd
Copy link

hfloyd commented Aug 2, 2018

@pedroadaodev - The easiest solution is to add this to the web.config:

<add key="Umbraco.ModelsBuilder.LanguageVersion" value="CSharp6" />

As per https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/83962-modelsbuilder-not-working-with-c6-code

@zpqrtbnk
Copy link
Collaborator

zpqrtbnk commented May 6, 2019

Not sure this is still an issue. Please re-open if I am wrong!

@zpqrtbnk zpqrtbnk closed this as completed May 6, 2019
@owlyowl
Copy link

owlyowl commented Aug 13, 2019

Hi I can confirm this is still an issue

UmbracoModelsBuilder: Starting v8.0.5 13-Aug-19 11:00:39 AM.
UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: NullReferenceException: Object reference not set to an instance of an object.
UmbracoModelsBuilder: at Umbraco.ModelsBuilder.CustomTool.VisualStudio.VisualStudioHelper.ClearExistingItems(ProjectItem sourceItem)
at Umbraco.ModelsBuilder.CustomTool.CustomTool.UmbracoModelsBuilder.GenerateRaw(String wszInputFilePath, String wszDefaultNamespace, IntPtr[] rgbOutputFileContents, UInt32& pcbOutput, String& errMsg)

I cannot for the life of me get it rebuilding. It worked properly the first few times and now no longer works at all. I tried clearing my models builder folder, deleting the generated models all that kind of stuff and cannot get it work

Does the custom tool store some cache somewhere on disk I need to clear?

@zpqrtbnk
Copy link
Collaborator

No it does not. This is weird. The exception happens after models have been generated, at the time we register them in the Visual Studio solution. Never seen an error there. Few questions:

What version of Visual Studio is this?

Any chance you can move to the new Extension (see https://www.zpqrtbnk.net/posts/models-builder-extension/) instead of the custom tool, and try again?

Any chance you could zip and share your entire project? You can reach me privately at [email protected].

@patmoe
Copy link

patmoe commented Jan 30, 2024

Seems like i got the same issue - however I get StackOverflow inbetween - after the generated models is deleted and before the generated models is created - #259
also see #257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants