Lancelot
Lancelot

Reputation: 2427

C# Error "Is not supported by the language" after migration to .Net4

I'm trying to migration our website from .Net 3.5 to 4 and I'm encountering a very weird issue.

Code that works just fine in 3.5 does not anymore once I target .Net4, giving me the error

"xxx is not supported by the language".

TimeZoneInfo tzi = !calendarItem.UseUserTimeZone ? user.Settings.TimeZoneInfo : l.TimeZoneItem.Info;

On that line of code the error shows on ".TimeZoneInfo" and ".Info" both of type "System.TimeZoneInfo".

Definition of user.Settings.TimeZoneInfo property is:

public TimeZoneInfo TimeZoneInfo
{
    get { return World.TimeZones[Convert.ToInt32(this[Setting.TimeZoneInfo])].Info; }
    set { this[Setting.TimeZoneInfo] = value.ToTimeZoneItem().Id.ToString(); }
}

Definition of l.TimeZoneItem.Info property is:

public TimeZoneInfo Info
{
    get { return info; }
}

Not really sure what's going on here. Need help on that one please.

Upvotes: 28

Views: 32969

Answers (8)

Jim
Jim

Reputation: 16022

For me this occurred due to a missing or out of date System.ValueTuple when using multiple return values in c# 7.

The error message is a bit misleading.

Upvotes: 5

Martin.Martinsson
Martin.Martinsson

Reputation: 2154

This also happens when an assembly is missing which is referenced by some other assembly in your project

Upvotes: 1

mslissap
mslissap

Reputation: 453

Similar to some of the other posts, in my case I was completely missing a reference to an assembly. It wasn't directly accessed from the project I was working with, but was accessed in another, linked project that I was referencing.

Upvotes: 1

yoel halb
yoel halb

Reputation: 12711

Similar to others here, if the referenced assembly is targeted to 'Any CPU', while the current assembly is targeted to 'Any CPU' will cause the problem (at least on a 64 bit machine).

Upvotes: 0

Rodrigo Caballero
Rodrigo Caballero

Reputation: 1170

Similiar to Jonathan Perry's answer, in my case I had a reference to an old assembly, not the compiled one. I removed the reference and added it again pointing to the correct dll.

Upvotes: 1

Patrick
Patrick

Reputation: 51

This also happens when a lower library is using a different versionof the .NET Framework. Had a similar issue and when I updated the Lower Libraries to 3.5 framework and the actual library to the 3.5 framework the problem went away.

Upvotes: 5

Jonathan Perry
Jonathan Perry

Reputation: 3053

It's probably an assembly inconsistency issue. I had this problem when I wanted to use an assembly that created a circular reference with another project. Once I fixed this circular reference issue, the error didn't appear anymore.

Upvotes: 20

Bek Raupov
Bek Raupov

Reputation: 3777

It might help to call property field differently. Because TimeZoneInfo is also a class in System namespace.

Upvotes: 1

Related Questions