Using `dynamic` keyword in C# doesn't compile
Asked Answered
L

1

3

I'm trying to compile a piece of C# code that contains the dynamic keyword. (I need this keyword for using ironpython.) However, it doesn't compile, complaining that

error CS1980: Dynamic keyword requires 
`System.Runtime.CompilerServices.DynamicAttribute' to be defined.
Are you missing System.Core.dll assembly reference?

The compiler I'm using is Mono JIT compiler version 2.10.8.1. I don't have System.Runtime.CompilerServices.DynamicAttribute in the list of possible references.

How can I make mono accept the dynamic keyword?

Leucine answered 22/9, 2013 at 13:12 Comment(11)
Do you have Mono's System.Core.dll referenced?Alchemize
Did you add references to System.Core.dll, Microsoft.Dynamic.dll and Microsoft.CSharp.dll?Dung
@Dung don't have either of them in my list.Leucine
You need to enable the C# 4 profile, sounds like you didn't. Google "__enable_profile4=yes"Osteogenesis
Thanks, I started working on an existing project that appeared configured to work with C# 2.0. -_-Leucine
You shouldn't NEED the dynamic keyword in your C# code.Easterly
@Easterly Please read the question before commenting. It's about working together with IronPython. The dynamic keyword is simply needed for that.Leucine
I was chasing the misinformation that you needed dynamic keyword in using the IronPython engine. You can instantiate the engine and expose typed objects to it. I haven't used the dynamic keyword in its context yet. You may need it to get objects back from the python. But it doesn't HAVE to be used that way.Easterly
The latter is exactly my use case. I need to retrieve python objects from a python library into the C# part.Leucine
So that use case you do need the keyword and .NET 4.0+. No bad blood was intended bro. Is this case closed? You should followup with a minipost and close it yourself. I just learned a lot about embedded IronPython and was browsing the not closed list.Easterly
Yeah, IronPython is an interesting technology. By the way, you are right that I should've marked this question as answered. Will do.Leucine
L
3

This comment of Hans Passant solved the problem:

You need to enable the C# 4 profile, sounds like you didn't. Google "__enable_profile4=yes"

Leucine answered 26/3, 2015 at 0:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.