I encounter with below mentioed errors when I am trying to write TTD for ‘ViewBag’ property in MVC3
//Error1Predefined type ‘Microsoft.CSharp.RuntimeBinder.Binder’ is not defined or importedTestProject1
//Error2One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?D:\MYPractice\MVC\RazorApplication\MVCDemo\TestProject1\UnitTest1.cs3113TestProject1
Controller :
public ActionResult Index()
{
ViewBag.Message = “Welcome to MVC3 demo”;
return View(“Index”);
}
MS Test :
public void TestMessage()
{
HomeController controler = new HomeController();
ViewResult res = controler.Index() as ViewResult;
Assert.AreEqual(“Welcome to MVC3 demo”, res.ViewBag.Message);
}
Solution :
1 . Right Click on MsTest project and select ‘Add reference’
2. Select ‘.Net’ tab in Add reference window.
3. Add select ‘Microsoft.CSharp.dll’ and click on add.
Now try to run test again.
ciarangallagher036 said:
This happened to me but have no idea why or how the reference got deleted…
ciarangallagher036 said:
On second thoughts, I’ve found out how. On VS2012 when looking as assemblies in the Reference Manager, it ticks all the assemblies you’ve referenced in your project. From my view, it looked like I had accidentally ticked the Microsoft.CSharp assembly, so I unticked it, and thus I unreferenced this. I’m more used to the VS2010 reference manager…
Nagi Setty A said:
Change the target framework version to .Net Framework 4.0.
then your problem will be resolved
dealer said:
My brother recommended I might like this blog.
He was entirely right. This post actually made my
day. You cann’t imagine just how much time I had spent for this info! Thanks!
cars said:
Car shopping can be very time consuming. There
are plenty of cars you can look at, as well as a handful of factors
to consider. You need to make sure you are aware of what
you need to make it a better experience. Consider the following helpful advice for making things easier on you.
cars said:
Car shopping is stressful. Now that there are hundreds of makes and models to
choose from, not to mention promotions and payment options,
it’s easy to become frustrated and stressed out. The information here will help make buying a car as easy and stress-free as possible.
Mememe said:
Solution is to add references to the compiler:
var ass = csprovider.CompileAssemblyFromSource(
new CompilerParameters {
GenerateInMemory = true,
CompilerOptions = “/r:\”” + SysRefl.Assembly.GetAssembly(typeof(Microsoft.CSharp.RuntimeBinder.Binder)).Location + “\” “+
“/r:\”” + SysRefl.Assembly.GetAssembly(typeof(System.Runtime.CompilerServices.CallSite)).Location + “\” ”
},
“yourcodehere”
);
C.L. Jones said:
Thank you!