I am trying to compile this code in Microsoft Visual C# 2010
using System;
using System.Globalization;
class main
{
static void Main()
{
dynamic d;
d = "dyna";
Console.WriteLine(d);
}
}
but I am getting these two errors
Error 1 Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported
Error 2 One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
I read this other post but I am new to C# and I couldn't understand what really is the problem. Especially what and where are these so called .config
files..
None of these worked for me.
My class libraries were definitely all referencing both System.Core and Microsoft.CSharp. Web Application was 4.0 and couldn't upgrade to 4.5 due to support issues.
I was encountering the error compiling a razor template using the Razor Engine, and only encountering it intermittently, like after web application has been restarted.
The solution that worked for me was manually loading the assembly then reattempting the same operation...
Hopefully this might help someone else out there.
On your solution explorer window, right click to References, select Add Reference, go to .NET tab, find and add Microsoft.CSharp.
Red lines under the ViewBag was my headache for 3 month ). Just remove the Microsoft.CSharp reference from project and then add it again.
For me, removing and re-adding a reference to Microsoft.CSharp fixed the problem temporarily until the affected file was edited. Closing Visual Studio and reopening the project fixed it more long-term, so that's an option if this situation occurs while Microsoft.CSharp is already referenced.
Maybe restarting the IDE as a first step seems trivial, but here's a reminder for people like me who don't think of that as the first thing to do.
I had the same problem and solved it by removing "Microsoft.CSharp" reference from the project and then added it again.
If you miss, Microsoft.CSharp.dll this error can occur. Check you project references.