Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1470 posts 3427 karma points c-trib
    Aug 08, 2018 @ 12:44
    Simon Dingley
    0

    ModelsBuilder: Feature 'expression body property accessor' is not available in C# 6. Please use language version 7.0 or greater

    I'm using ModelsBuilder API to generate my models in Visual Studio using the Visual Studio extension. I can not generate my models currently and the following output is shown in the output window of Visual Studio:

    UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: Exception: Response status code does not indicate success (InternalServerError)
    {"Message":"An error has occurred.","ExceptionMessage":"Feature 'expression body property accessor' is not available in C# 6. Please use language version 7.0 or greater.","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)
    

    Unfortunately, even in debug mode, there is nothing in the log files. The error gives no indication as to where the problem might exist and as far as I can tell I have no partial classes that are using expression body property accessors. I only have one partial class that adds an additional property to one of the models using the traditional block body approach as follows:

    public partial class News
    {
        private IEnumerable<NewsArticle> articles;
    
        public IEnumerable<NewsArticle> Articles
        {
            get
            {
                return articles ?? this.Content.Children<NewsArticle>();
            }
    
            set
            {
                this.articles = value;
            }
        }
    }
    

    My appsettings for ModelsBuilder are as follows:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="" />
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true" />
    <add key="Umbraco.ModelsBuilder.LanguageVersion" value="CSharp6" />
    

    And I have the following packages installed after upgrading Microsoft.CodeAnalysis.Analyzers in the hope of rectifying the problem.

    <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net471" />
    <package id="Microsoft.CodeAnalysis.Common" version="2.8.2" targetFramework="net471" />
    <package id="Microsoft.CodeAnalysis.CSharp" version="2.8.2" targetFramework="net471" />
    <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net471" />
    

    Any ideas where to go next with this?

    Edit: I should also note that if I change my ModelsMode to AppData I can successfully generate the models via the Developer section.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Aug 08, 2018 @ 13:10
    Nik
    100

    Hi Simon,

    I think you need to edit this config line:

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

    I think you need to change it to have a value of CSharp7 but I'm not 100%.

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Aug 08, 2018 @ 13:22
    Simon Dingley
    0

    Thanks Nik - that did the trick! I didn't think it was supported, at least not according to the docs. However, it still doesn't explain why this was happening in the first place when I am not implementing the expression bodied properties in any of my models. I've burnt enough time on this now so will have to just accept that it now works so I can move on but it will continue to bug me I'm sure :(

Please Sign in or register to post replies

Write your reply to:

Draft