Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type 'System.IDisposable' is defined in an assembly that is not referenced

Tags:

c#

.net

windows

I created a Windows Form application in Visual Studio 2012 on Windows 8, and the target .NET framework is 4.5, and I want to use the Datagramsocket library of Windows SDK, so I changed the target OS version to 8, when I compile.

I am getting the following error:

"Error 1 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'."

like image 631
jiali passion Avatar asked Sep 10 '12 09:09

jiali passion


2 Answers

If you are targeting Windows 8, the MSDN documentation has the following instructions:

That said, your desktop app can’t consume much of anything from the Windows Runtime until you prepare your project with one essential reference. The Windows Runtime defines some standard classes and interfaces in System.Runtime, such as IEnumerable, that are used throughout the Windows Runtime libraries. By default, your managed desktop app won’t be able to find these types, and so you must manually reference System.Runtime before you can do anything meaningful with Windows Runtime classes. To create this manual reference:

  1. Navigate to your managed desktop app project in the Solution Explorer.
  2. Right-click the References node and click Add Reference.
  3. Click the Browse tab.
  4. Click Browse….
  5. Navigate to the System.Runtime.dll façade. You can generally find this in a path similar to: %ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Runtime.dll

Hope that helps.

like image 118
Nathan Avatar answered Sep 22 '22 13:09

Nathan


If you run into this problem with 4.5.2 and Unity, Microsoft has issued a fix, KB article: http://support.microsoft.com/kb/2971005

like image 41
Josh Avatar answered Sep 22 '22 13:09

Josh