简体   繁体   English

将项目的.NET目标框架从4.0更改为3.5后,找不到文件(或程序集)

[英]File (or assembly) can't be found after changing project's .NET target-framework from 4.0 to 3.5

I want to change my C# project, which is based on the .NET 4.0 to 3.5. 我想改变我的C#项目,它基于.NET 4.0到3.5。 So I changed the project's target-framework to 3.5. 所以我将项目的目标框架更改为3.5。

After re-opening and trying to compile the project I get the error: 重新打开并尝试编译项目后,我收到错误:

The file or assembly "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of its dependencies couldn't be found. 无法找到文件或程序集“System.Drawing,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”或其中一个依赖项。 The system can't find the file. 系统找不到该文件。 oder eine Abhängigkeit davon wurde nicht gefunden. odereineAbhängigkeitdavonwurde nicht gefunden。 Das System kann die angegebene Datei nicht finden. Das System kann die angegebene Datei nicht finden。

This happens in the file Resource.resx, which looks like that: 这发生在Resource.resx文件中,如下所示:

<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <data name="traktor_connected" type="System.Resources.ResXFileRef, System.Windows.Forms">
        <value>..\Resources\traktor_connected.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
    </data>
    <data name="traktor_not_connected" type="System.Resources.ResXFileRef, System.Windows.Forms">
        <value>..\Resources\traktor-not-connected.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
    </data>

That reference is pointing to .Net 4 - you need to remove all .net 4 references and then readd them using the .net 3.5 version of the assemly and then it will work 该引用指向.Net 4 - 您需要删除所有.net 4引用,然后使用.net 3.5版本的组件读取它们然后它将工作

paul 保罗

Changing the Target framework setting is not exactly perfect. 更改目标框架设置并不完美。 In a C# project for example you have to remove the reference to Microsoft.CSharp by hand. 例如,在C#项目中,您必须手动删除对Microsoft.CSharp的引用。 And yes, it doesn't automatically update the System.Drawing assembly references in the .resx files. 是的,它不会自动更新.resx文件中的System.Drawing程序集引用。 This is quite a flaw, works okay when you increase the .NET version number (what just about everybody normally does), kaboom if you try to decrease it. 这是一个相当大的缺陷,当你增加 .NET版本号(几乎每个人通常都会这样做)时可以正常工作,kaboom如果你试图减少它。 .NET is only forward compatible. .NET只是向前兼容。

You'll have to remove the resources and add them back after changing the target framework. 在更改目标框架后,您必须删除资源并将其添加回来。 Pretty painful, editing the .resx file by hand to minimize the job is however possible. 非常痛苦,可以手动编辑.resx文件以最小化工作。 Right-click the .resx file, Open With and select the text editor. 右键单击.resx文件,打开方式,然后选择文本编辑器。 Change the Version for the assembly name from 4.0.0.0 to 2.0.0.0. 将程序集名称的版本从4.0.0.0更改为2.0.0.0。

Beware however that there can be trickier resources, like ImageList, the kind whose data got embedded in the .resx in binary. 但请注意,可能存在比较复杂的资源,如ImageList,其数据以二进制形式嵌入.resx中。 You'll see a blob of base64 encoded bytes in the .resx file. 您将在.resx文件中看到一小块base64编码的字节。 That also has the version number embedded, done so by BinaryFormatter. 它也嵌入了版本号,由BinaryFormatter完成。 The possible reason that VS doesn't do this for you. VS不会为你做这件事的可能原因。 Writing a little program that decodes that base64 string back to byte[], locates the proper 0x34 and changes it to 0x32 and converts it back to base64 is only a hacker's delight, man over machine style :) Best to just re-add those to avoid the almost inevitable oopses. 编写一个将base64字符串解码回byte []的小程序,找到正确的0x34并将其更改为0x32并将其转换回base64只是一个黑客的喜悦,男人超过机器风格:)最好只重新添加到避免几乎不可避免的oopses。

I had this error when I installed a COM component in NET 4.5 then downgraded to NET 4.0. 我在NET 4.5中安装COM组件然后降级到NET 4.0时出现此错误。 Removing and adding the reference made no difference. 删除和添加引用没有区别。

I found this helpful. 我觉得这很有帮助。

* Solution or Workaround Change the default Platform Target CPU to allow applications to run on 64-bit machines. * 解决方案或解决方法更改默认的平台目标CPU,以允许应用程序在64位计算机上运行。 * *

http://forums.arcgis.com/threads/19335-COM-Exception-was-unhandled-and-Class-not-registered http://forums.arcgis.com/threads/19335-COM-Exception-was-unhandled-and-Class-not-registered

The NET 4.0 target environment for me is 32bit, so I get the Target CPU down to x86 in the properties window. 对我来说,.NET 4.0目标环境是32位,因此我在属性窗口中将目标CPU降低到x86。 Now it runs. 现在它运行了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM