Use the dynamic keyword/.NET 4.6 feature in Unity

Viewed 8531

I am trying to implement GraphQL into Unity3D (version 2017.1.0f3 Personal). I am using .NET 4.6 (Experimental), but despite this, Unity does not support dynamic keyword. Which is odd, since .NET 4.0 it is the part of .NET. Except in Unity. I was googling for some solution how to get it work, but no solutions to the dynamic keyword. The error is this:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1980  Cannot define a class or member that utilizes 'dynamic' 
because the compiler required type 
'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you 
missing a reference?    skiing-prototype (1)    D:\skiing-prototype 
(1)\Assets\Scripts\GraphQL.cs   62  Active

That is the only caveat of using GraphQL C# client. Has anyone tried it yet to get it work? I hadn't found any greater efforts to get it up and running yet.

EDIT:

I am using this client here: https://github.com/bkniffler/graphql-net-client

Also this is an error from visual studio, but in Unity console it shows errors too, will update what exactly momentarily

Assets/Scripts/GraphQL.cs(80,16): error CS1980: Dynamic keyword requires 
`System.Runtime.CompilerServices.DynamicAttribute' to be defined. Are you 
missing System.Core.dll assembly reference?

this is the unity editor error, which seems to be the same that in visual studio

2 Answers

I seem to have found a solution

Navigate to Edit > Project Settings > Player > Other Settings > Configuration > API Compatibility Level and change from .NET Standard 2.0 to .NET 4.x

This immediately removed the compiler error and allowed me to run code using the dynamic keyword.

Let me know if that was useful

Related