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>
4
  • 1
    Have you explicitly added the reference to the assembly? Removed and re-added? Commented Jul 1, 2015 at 10:34
  • Please see this link stackoverflow.com/questions/20660999/… This should resolve your problem Commented Jul 1, 2015 at 10:41
  • 1
    @Chander.k unable to get this answer ? can you specifically elaborate for my problem ? Commented Jul 1, 2015 at 10:43
  • What is the code you are compiling? Commented Jul 1, 2015 at 10:45

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

5 Comments

this resolved my specific system runtime dll error but i wonder why this is not resolved when I have added it in web.config?
Because compiling the code has nothing to do with your currently running code. You need to tell the compiler how to compile.
that is why it does not read it from web.config you mean to say?
Indeed. Why should it? What if you want to compile for another version of the assembly?
cool great thanks a lot, actually everywhere only web.config tag solution is given thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.