2

I'm getting runtime error about missing reference.

The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

I'm using MVC application and used CSharpCodeProvider inside my code.

I do not get any compile error but getting runtime error for compileResult as above why?

 CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);

I even added assemblies tag in web.cofig like following still same error.any clue why?

  <assemblies>     
    <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
  </assemblies>
Neo
  • 15,491
  • 59
  • 215
  • 405

1 Answers1

2

ASP.NET MVC uses the dynamic keyword a lot. That may be the original of the problem, since that requires both the Microsoft.CSharp assembly (which you have obviously included) and the System.Runtime assembly (I think this one is missing.

Add the System.Runtime assembly in your compile config:

parameters.ReferencedAssemblies.Add("mscorlib.dll"); // guess you have this one already
parameters.ReferencedAssemblies.Add("System.Runtime.dll");
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • this resolved my specific system runtime dll error but i wonder why this is not resolved when I have added it in web.config? – Neo Jul 01 '15 at 10:45
  • 1
    Because compiling the code has nothing to do with your currently running code. You need to tell the compiler how to compile. – Patrick Hofman Jul 01 '15 at 10:46
  • that is why it does not read it from web.config you mean to say? – Neo Jul 01 '15 at 10:49
  • Indeed. Why should it? What if you want to compile for another version of the assembly? – Patrick Hofman Jul 01 '15 at 10:50
  • 1
    cool great thanks a lot, actually everywhere only web.config tag solution is given thanks :) – Neo Jul 01 '15 at 10:52