I’m trying to use dynamic keyword and I’m getting the compiler error from VS 2017:
Error CS0656 Missing compiler required member ‘Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create’
I followed the below link but it didn’t work for the dynamic keyword. The other features on this post don’t give me any errors though (Index Initializers, String Interpolation) so it seems like I am using C# 6 features but dynamic keyword just doesn’t compile for me.
Before I installed VS Unity Tools I was able to add a reference to make this work but then I wasn’t able to debug without the tools. When I installed the tools now it doesn’t let you add references. So I’m kind of stuck. Any help would be great!
The solution is not complicated, we need to modify csproj file generated by VSTU, and add Microsoft.CSharp. I wrote simple project generation hook to automate this:
[InitializeOnLoad]
public class ProjectFileHook
{
private static string msBuildNs = "http://schemas.microsoft.com/developer/msbuild/2003";
// necessary for XLinq to save the xml project file in utf8
class Utf8StringWriter : StringWriter
{
public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
}
static ProjectFileHook()
{
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
if (name.Contains("Editor"))
{
// parse the document and make some changes
var document = XDocument.Parse(content);
XElement itemGroup = new XElement(XName.Get("ItemGroup", msBuildNs));
XElement reference = new XElement(XName.Get("Reference", msBuildNs));
reference.Add(new XAttribute(XName.Get("Include"), "Microsoft.CSharp"));
itemGroup.Add(reference);
document.Root.LastNode.AddAfterSelf(itemGroup);
// save the changes using the Utf8StringWriter
var str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
}
return content;
};
}
}
This add missing reference only to Editor assemblies, and resolves compilation error in Visual Studio, I don’t think dynamic is supported on all the platforms.
It would be actually nice if VSTU team could add this reference to their csproj file generation routine.
I just can’t get this to work, the line is not added to the csproj… I tried adding the reference “by hand”, and it compile but unity still show the error in the console and if I close and reopen the project, it removes the reference.
The script is meant to fix only Editor assemblies, there is a condition in line 20.
I’m not sure if dynamic is supported in a build assemblies, that’s why I added the condition., if your assembly that you are trying to fix is not Editor-only you can try to comment the mentioned line and see the effects, however I encourage you to test the build result after that.
Thanks for the reply, I can’t get this to work even in the editor, I have exactly the same error as the original post in the editor’s console, so I can’t hit play nor build