Closed ghost closed 5 years ago
going to guess here... what happens if you replace the lines
if (decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal result))
return result;
with
decimal result;
if (decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
return result;
?
The error we're seeing is, we fail to parse your code. And yet, your code is valid. But the syntax you used was introduced in C# version I-cannot-remember. In order for your syntax to be supported, you may want to experiment with the Umbraco.ModelsBuilder.LanguageVersion
configuration setting (see Install And Configure) and use something like CSharp7
.
Does this help?
Yup, that helps! I was under the impression that it was due to the nullable return type, but indeed it was the usage of the so-called Out variables introduced in C# 7.
We have ModelsBuilder 3.0.10 installed but changing the Umbraco.ModelsBuilder.LanguageVersion value to CSharp7 throws an "Invalid language version 'CSharp7'" ConfigurationErrorsException. In what version of ModelsBuilder is support for C# 7 introduced? Or am I missing another setting somewhere?
[ConfigurationErrorsException: Invalid language version "CSharp7".]
Umbraco.ModelsBuilder.Configuration.Config..ctor() in D:\d\Zbu ModelsBuilder-7\Umbraco.ModelsBuilder\Configuration\Config.cs:126
Umbraco.ModelsBuilder.Configuration.<>c.<ModelsBuilder>b__1_0() in D:\d\Zbu ModelsBuilder-7\Umbraco.ModelsBuilder\Configuration\UmbracoConfigExtensions.cs:24
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Func`1 valueFactory) +21
Umbraco.ModelsBuilder.Configuration.UmbracoConfigExtensions.ModelsBuilder(UmbracoConfig umbracoConfig) in D:\d\Zbu ModelsBuilder-7\Umbraco.ModelsBuilder\Configuration\UmbracoConfigExtensions.cs:25
Umbraco.ModelsBuilder.Umbraco.LiveModelsProvider.get_IsEnabled() in D:\d\Zbu ModelsBuilder-7\Umbraco.ModelsBuilder\Umbraco\LiveModelsProvider.cs:26
Umbraco.ModelsBuilder.Umbraco.LiveModelsProviderModule.Install() in D:\d\Zbu ModelsBuilder-7\Umbraco.ModelsBuilder\Umbraco\LiveModelsProvider.cs:132
[InvalidOperationException: The pre-application start initialization method Install on type Umbraco.ModelsBuilder.Umbraco.LiveModelsProviderModule threw an exception with the following error message: Invalid language version "CSharp7"..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +850
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +162
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +128
System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +820
[HttpException (0x80004005): The pre-application start initialization method Install on type Umbraco.ModelsBuilder.Umbraco.LiveModelsProviderModule threw an exception with the following error message: Invalid language version "CSharp7"..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +523
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +107
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +688
Roslyn as shipped with ModelsBuilder for v7 stops at CSharp6
and does not support C# 7 indeed.
And... there is no plan to change this for v7.
Allright, then this issue can be closed ;-) And I think one should update the documentation on ModelsBuilder with this limitation.
For a reason, I have some string properties on my document type, as these have a Label as their editor. The values of these properties are imported (and should not be editable in Umbraco). I'm using ModelsBuilder but when I define the following on my model, the ModelBuilder fails with the message below.
This results in the following message:
Commenting out the properties resolves the issue, and having them as nullable too. But that's not really an option...