Closed mattbrailsford closed 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.
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.
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?
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.
Ahh, that might be it, I think lambda get
is CSharp7
feature, public string Rel => Target == "_blank" ? "nofollow" : "";
works fine (ie, no explicit get
)
Thanks for the speedy help. I really appreciate it 👍
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
Any ideas what could be causing this?