Unity upgrade from 3.0 to 3.5 throwing a "System.Runtime is not referenced"

Apr 26 at 11:28 AM
Edited Apr 26 at 11:29 AM
Hi there,

We've migrated Unity from 3.0.1304.1 to 3.5.1404.0 via Nuget and now our build server is throwing the exception "error CS0012: The type 'System.IDisposable' 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'." when compiling the solution, pointing to a class using the IUnityContainer interface.

We're running .NET 4.5.
Locally the code compiles and runs just fine without any change besides updating Unity via NuGet.
In the build server I made sure old files were cleaned up but still can't get rid of this exception when compiling the sources.

Does anyone has an idea on how to solve this ?

Thanks in advance!

Best regards,
Ricardo
Apr 30 at 9:22 PM
Did you have to do anything special to get compiling locally? Currently mine does not and am trying to figure out why.
Apr 30 at 9:47 PM
Compiling locally works fine, i just added Unity via NuGet and update the config files manually because there is a config section where the unity version is specified.
My issue is strange because it occurs only in the build server.
Apr 30 at 9:53 PM
Edited Apr 30 at 9:55 PM
I referenced C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime which seems to have fixed it locally, may not be on your build server.

See: http://stackoverflow.com/questions/12349189/the-type-system-idisposable-is-defined-in-an-assembly-that-is-not-referenced
Editor
May 2 at 4:55 AM
Unity 3.5 is now a Portable Class Library and references .NET Portable Subset (Profile78). It sounds like the build server might not have those libraries installed. Can you verify that those assemblies are installed on the build machine?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
May 8 at 4:34 PM
Edited May 8 at 4:37 PM
This is happening to me to on our build server. Works fine locally in Visual Studio, fails under TFS 2013 build running on vanilla Windows Server 2012 R2 .. that, according to the installer, already has .NET 4.5.1 installed. Build server does not have VS2013 installed.


" The type 'System.IDisposable' 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'."
Can you verify that those assemblies are installed on the build machine?
Apologies, but how?

... it may be my lack of understanding but how come the unity package doesn't handle this?

I really don't want to have the hack of adding a reference to the facades folder... :(
Editor
May 25 at 7:22 AM
Are you targetting 4.5.2? If so, there is an issue on connect with framework version numbers which cause a build to fail when referencing a PCL.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jun 4 at 5:21 PM
Edited Jun 4 at 6:13 PM
I reproduced this problem in another project, and I would like to get more information about it

I created an empty mvc application and added just the unity nuget package

then I added this code to the home controller
namespace Mvc.Controllers
{
    public class HomeController:Controller
    {
        public ActionResult Index()
        {
            var container = new Microsoft.Practices.Unity.UnityContainer();
            return View();
        }
    }
}
this code worked fine, compiled and executed without errors.

then I put this line in my razor view
@{
    Layout = null;
    var container = new Microsoft.Practices.Unity.UnityContainer();
    
}
and when I run I the same CS0012: The type 'System.IDisposable' 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'.

why this happens in the view but it doesn't happen in the controller?


Update:

I found this link that explains this.

link