类型“System.IDisposable的”在未被引用的程序集中定义未被、定义、类型、程序

2023-09-03 00:05:29 作者:十里顾清欢

我创造了在Visual Studio 2012年Windows窗体应用程序在Windows 8上,而目标.NET框架4.5,我想使用Windows SDK的DatagramSocket的库,所以我改变了目标OS版本8,当我编译。

我收到以下错误:

  

类型System.IDisposable的在未被引用的程序集中定义错误1。你必须添加一个引用程序集System.Runtime,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a。

解决方案

如果您正在针对Windows 8的的 MSDN文档有如下说明:

  

这是说,你的桌面应用程序不能消耗太多的东西   Windows运行时,直到$ P $一个重要的ppare项目   参考。 Windows运行时定义了一些标准类和   在 System.Runtime 的接口,如的IEnumerable ,所使用的   整个Windows运行时库。默认情况下,您的管理   桌面应用程序将无法找到这些类型的,所以你必须   手动引用System.Runtime之前,你可以做任何事情   有意义的Windows运行时类。要创建本手册   参考:

        导航到在解决方案资源管理器管理的桌面应用程序的项目。   右键单击引用节点,然后单击添加引用。   点击浏览标签。   点击浏览...   导航到System.Runtime.dll外观。您通常可以找到这个在类似的路径:的%ProgramFiles(x86)的%\参考大会\微软\框架\ .NETFramework \ V4.5 \外立面\ System.Runtime.dll   

希望有所帮助。

无法将类型为System.Int32的对象强制转换为类型System.String

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

解决方案

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:

Navigate to your managed desktop app project in the Solution Explorer. Right-click the References node and click Add Reference. Click the Browse tab. Click Browse…. 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.