2
votes

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>
1
Have you explicitly added the reference to the assembly? Removed and re-added?Grant Thomas
Please see this link stackoverflow.com/questions/20660999/… This should resolve your problemChander .k
@Chander.k unable to get this answer ? can you specifically elaborate for my problem ?Neo
What is the code you are compiling?Patrick Hofman

1 Answers

2
votes

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");