modelsbuilder / ModelsBuilder.Original

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

{ or ; expected #171

Closed mattbrailsford closed 6 years ago

mattbrailsford commented 6 years ago

Hi,

I'm using the models builder custom VS tool and it's all been working fine, but when I come to run it today it's failing with the message "the custom tool umbracomodelsbuilder failed" with the following stack trace

UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: Exception: Response status code does not indicate success (InternalServerError)
{"Message":"An error has occurred.","ExceptionMessage":"{ or ; expected","ExceptionType":"Umbraco.ModelsBuilder.Building.CompilerException","StackTrace":"   at Umbraco.ModelsBuilder.Building.Compiler.ThrowExceptionFromDiagnostic(String path, String code, Diagnostic diagnostic) in D:\\d\\Zbu ModelsBuilder-7\\Umbraco.ModelsBuilder\\Building\\Compiler.cs:line 161\r\n   at Umbraco.ModelsBuilder.Building.Compiler.<>c__DisplayClass12_0.<GetCompilation>b__0(KeyValuePair`2 x) in D:\\d\\Zbu ModelsBuilder-7\\Umbraco.ModelsBuilder\\Building\\Compiler.cs:line 50\r\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\r\n   at Umbraco.ModelsBuilder.Building.Compiler.GetCompilation(String assemblyName, IDictionary`2 files, SyntaxTree[]& trees) in D:\\d\\Zbu ModelsBuilder-7\\Umbraco.ModelsBuilder\\Building\\Compiler.cs:line 46\r\n   at Umbraco.ModelsBuilder.Building.CodeParser.Parse(IDictionary`2 files, IEnumerable`1 references) in D:\\d\\Zbu ModelsBuilder-7\\Umbraco.ModelsBuilder\\Building\\CodeParser.cs:line 38\r\n   at Umbraco.ModelsBuilder.Api.ApiHelper.GetModels(String modelsNamespace, IDictionary`2 files) in D:\\d\\Zbu ModelsBuilder-7\\Umbraco.ModelsBuilder\\Api\\ApiHelper.cs:line 16\r\n   at Umbraco.ModelsBuilder.Api.ModelsBuilderApiController.GetModels(GetModelsData data) in D:\\d\\Zbu ModelsBuilder-7\\Umbraco.ModelsBuilder.Api\\ModelsBuilderApiController.cs:line 65\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\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.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>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)

Any ideas what could be causing this?

zpqrtbnk commented 6 years ago

The exception is thrown when parsing one of the local (partial) files that you have in your solution. Any *.cs file in the models directory is sent by the custom tool to the server, where it is parsed, looking for attributes that could control model generation. If these files are seen as totally OK by VS yet trigger the exception... especially a "missing { or ;"... my first thought would be that the server-side code is not using the correct C# version to parse the files.

Do you have a LanguageVersion app settings for MB and what is its value?

As for why it's happening now, I don't know yet.

mattbrailsford commented 6 years ago

I added a <add key="Umbraco.ModelsBuilder.LanguageVersion" value="CSharp6" /> line to the web.config this morning to see if that would fix it, but it didn't. I'll go double check my models and see if I can spot an issue.

mattbrailsford commented 6 years ago

Ok, I found the culprite which does look to be a language version issue. I had a model with a property with a getter like so:

public string Rel
{
    get =>  Target == "_blank" ? "nofollow" : "";
}

replacing it with the following makes it run fine:

public string Rel
{
    get
    {
        return Target == "_blank" ? "nofollow" : "";
    }
}

Does the LanguageVersion setting need to be in the config file for the class library project where your models live? or should it just need to live in the web projects config?

zpqrtbnk commented 6 years ago

Could you have some CSharp7 code in your partials? eg public string MyProperty => "foo";?

'cos then, CSharp6 would not support it, and probably trigger the kind of exception you're seeing. And I cannot remember whether CSharp7 would be supported by the (old) version of Roslyn that we (still) use.

mattbrailsford commented 6 years ago

Ahh, that might be it, I think lambda get is CSharp7 feature, public string Rel => Target == "_blank" ? "nofollow" : ""; works fine (ie, no explicit get)

mattbrailsford commented 6 years ago

Thanks for the speedy help. I really appreciate it 👍