superjos superjos - 17 days ago 11
C# Question

BindingFlags does not exist in .NET Core netstandard 1.2 class library

In a .NET Core class library project targeting both

net452
and
netstandard1.3
frameworks, I'm trying to move the latter backwards to
netstandard1.2
in order to extend back-compatibility.

Project uses
BindingFlags
enum and builds fine on net452, as well netstandard1.3, but it fails on netstandard1.2 with a number of errors, all looking either like:


CS0103 The name 'BindingFlags' does not exist in the current context


or like:


CS7069 Reference to type 'BindingFlags' claims it is defined in 'System.Reflection', but it could not be found


Currently,
frameworks
attribute in project.json is:

"frameworks": {
"netstandard1.2": {
"imports": [
"dnxcore50",
],
"dependencies": {
"NETStandard.Library": "1.6.0",
"runtime.any.System.Collections": "4.0.11",
"System.Collections": "4.0.11",
"System.Collections.NonGeneric": "4.0.1",
"System.Console": "4.0.0",
"System.IO.FileSystem": "4.0.1",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Runtime.Serialization.Xml": "4.1.1",
"System.Text.Encodings.Web": "4.0.0"
}
},
"net452": {
"frameworkAssemblies": {
"System.IO": "",
"System.Runtime.Serialization.Xml": "",
"System.Xml": "",
"System.Web": ""
}
}
},


and it already lists dependency from
System.Reflection.TypeExtensions
.

Show potential fixes popup suggests to install
"System.Reflection": "4.3.0-preview1-24530-04"
, only to find that type still shows with the red squiggly line. Another Show potential fixes popup this second time suggests to install
"System.Reflection.TypeExtensions": "4.3.0-preview1-24530-04"
. Of course without affecting the error, that's still there.

Building net452 side goes fine, errors are only on
netstandard1.2
build.

What's wrong with this
BindingFlags
type?

Answer

According to the netstandard 1.5 diff the BindingFlags enum was added to the standard in the 1.5 version.

Before it was available through the System.Reflection.TypeExtensions package which only supports 1.3 or later so targetting 1.2 doesn't work.

Comments