Xamarin.iOS CS8370 Feature 'range operator' is not available in C# 7.3. Please use language version 8.0 or greater

Oleksandr Ragoza

New member
Joined
Jul 20, 2022
Messages
2
Programming Experience
Beginner
I'm trying to follow one of the tutorial for Xamarin application. My VS is: Microsoft Visual Studio Community 2019 Version 16.11.17 VisualStudio.16.Release/16.11.5+31729.503 Microsoft .NET Framework Version 4.8.04084
The stucture of my Xamarin solution is:

GalleryApp
Models
IPhotoImporter
GalleryApp.Android
GalleryApp.IOS
PhotoImporter : IPhotoImporter

After a while, I've reached the chapter, which produces the following code (in iOS project in PhotoImporter class):
C#:
foreach (PHAsset asset in results[startIndex..endIndex])
{
    var filename = (NSString)asset.ValueForKey((NSString)"filename");            
    RequestImage(photos, asset, filename, options);
}
return photos;

this code [startIndex..endIndex] throws an error: Error CS8370 Feature 'range operator' is not available in C# 7.3. Please use language version 8.0 or greater.
In the C# project (GalleryApp) I've modified the project file:

C#:
<PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>

but the error is still there.
I've inserted this line of code (#error version) to the GalleryApp.Models.IPhotoImporter:
result: Error CS8304 Compiler version: '3.11.0-4.22108.8 (d9bef045)'. Language version: 8.0.

and to the GalleryApp.IOS.PhotoImporter:
result: Error CS8304 Compiler version: '3.11.0-4.22108.8 (d9bef045)'. Language version: 7.3. GalleryApp.iOS

It means, that by modifying the Project file the following tag <LangVersion>8.0</LangVersion> will affect to the particular project, but not by the solution in general.

Than, I was trying to modify the property of the Gallery.IOS project (by choosing the specific version of the C# = 8.0) -> Properties -> Build -> Advances = but the Language version is not editable - (The latest C# compiler determines a default language version based on your project's target framework or frameworks) - my target framework for this solution is 2.1 and I'm not able to choose another version (3.0) in the lookup.

I've asked this question in the stackoverflow and I've receive one comment (which I've tried but it doesn't helped)
The comment from stackoverflow:
"You can't (currently) change xamarin to anything newer than .netstandard2.1. But that should automatically support c# 8, so the error is puzzling. First, make sure Visual Studio is up to date. Then, I recommend creating a new xamarin project, and testing c# 8 features in that. If that works, then it may be easiest to add all your source files to that new project. Alternatively, compare its csproj to yours - there must be some difference.
ToolmakerSteve
Jul 16 at 18:11"

Any idea how to overcome this?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,712
Location
Chesapeake, VA
Programming Experience
10+
I've only skimmed your post, but I got the feeling that you created your project as a .NET Framework 4.8 project instead of a .NET Core 3 or higher project. As I recall, .NET Framework tops off at C# 7.3.
 

Oleksandr Ragoza

New member
Joined
Jul 20, 2022
Messages
2
Programming Experience
Beginner
I've only skimmed your post, but I got the feeling that you created your project as a .NET Framework 4.8 project instead of a .NET Core 3 or higher project. As I recall, .NET Framework tops off at C# 7.3.
I'm not sure that I'm fully understand your comment, do you suggest create another solution and choose .NET Core 3? (if - yes, I'm not sure how to do this, but ok, I will try to find out)
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,712
Location
Chesapeake, VA
Programming Experience
10+
I don't know either. Sorry.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,712
Location
Chesapeake, VA
Programming Experience
10+
Also contact the tutorial author(s). They may have some advice

In the meantime, the range operator is just syntactic sugar. You can always rewrite to use a regular for loop to access those items in the list/array.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,712
Location
Chesapeake, VA
Programming Experience
10+
Looks like your book/tutorial already addresses this:
Screenshot_1.png


And then scrolling back in Google:
Screenshot_2.png
 
Top Bottom