简体   繁体   English

强命名程序集在我的Visual C#中不起作用

[英]Strong named assembly not working in my Visual C#

I have a project and I want to strong name the executable file. 我有一个项目,我想强命名可执行文件。 Using command-line compiling works well: 使用命令行编译效果很好:

csc ... /keyfile:... csc ... / keyfile:...

But I would like the IDE to do this, so I find this: in project property's `Signing' tab, there is a 'Sign the assembly' option. 但是我希望IDE能够做到这一点,所以我发现了这一点:在项目属性的“签名”选项卡中,有一个“签名程序集”选项。 I tick it and direct to my key-pair file. 我勾选它并直接指向我的密钥对文件。 After I lauch the debug, a FileNotFound exception shows up at an indifferent place: (my application uses serialization) 在取消调试之后,一个无关紧要的地方会出现FileNotFound异常:(我的应用程序使用序列化)

        protected override Type d(Stream st)
        {
            BinaryFormatter bf = new BinaryFormatter();
            return (Type)bf.Deserialize(st);
        }

The application was doing right before I do this configureation. 在执行此配置之前,该应用程序运行正常。

You will need to appropriately configure the Binder property of the BinaryFormatter. 您将需要适当地配置BinaryFormatter的Binder属性。 Here is an example of how to do this: http://spazzarama.wordpress.com/2009/06/25/binary-deserialize-unable-to-find-assembly/ 这是如何执行此操作的示例: http : //spazzarama.wordpress.com/2009/06/25/binary-deserialize-unable-to-find-assembly/

I assume you are reading back data that was written with the unsigned application. 我假设您正在回读使用未签名的应用程序写入的数据。 That data has now become incompatible, the Deserializer can't match the types. 该数据现在变得不兼容,反序列化器无法匹配类型。

I'm not sure how to fix this (quickly), but maybe you can confirm this first by writing and reading with the signed application, that should work. 我不确定如何(快速)解决此问题,但是也许您可以首先通过使用签名的应用程序进行写入和读取来确认此问题,这应该可以工作。

It is a good idea to keep all your serialized types in a separate assembly. 最好将所有序列化类型放在单独的程序集中。

Both of the responses were excellent. 两种反应都很好。
Adding my 1 pence to it: This is called TYPE FIDELITY which is possible only through Binary serialization and not in XML or any other type of serialization. 在其中添加我的1便士:这就是所谓的TYPE FIDELITY ,它只能通过二进制序列化来实现,而不能以XML或任何其他类型的序列化来实现。

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

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