Visual Studio 错误地将数据添加到 Resx 文件 [英] Visual Studio Erroneously Adding Data To Resx File

查看:24
本文介绍了Visual Studio 错误地将数据添加到 Resx 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 DocumentExplorerControl 的自定义用户控件,它具有多个属性,其中之一称为 HistoryList.如果我对包含此控件的任何表单进行任何更改,构建将失败并显示以下错误:

I have a custom user control called DocumentExplorerControl, which has several properties, one of which is called HistoryList. If I make any change to any form that contains this control, the build will fail with the following error:

Invalid Resx file. Could not load type System.Collections.Generic.List`1[[xxxxxx.DocumentManager.IHistoryObject, xxxxxx, Version=4.0.5207.25065, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 which is used in the .RESX file.

我可以双击错误,它会将我带到 .resx 文件中的问题:

I can double-click the error and it takes me to the problem in the .resx file:

  <data name="documentsList.HistoryList" mimetype="application/x-microsoft.net.object.binary.base64">
    <value>
        AAEAAAD/////AQAAAAAAAAAMAgAAAJkBQURNU19EZXNrdG9wLCBWZXJzaW9uPTQuMC41MjA3LjI1MDY1
        LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPW51bGxdXSwgbXNjb3JsaWIsIFZlcnNpb249
        NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5DAMA
        AABKQURNU19EZXNrdG9wLCBWZXJzaW9uPTQuMC41MjA3LjI1MDY1LCBDdWx0dXJlPW5ldXRyYWwsIFB1
        YmxpY0tleVRva2VuPW51bGwFAQAAAE5TeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5MaXN0YDFbW0FE
        TVNfRGVza3RvcC5Eb2N1bWVudE1hbmFnZXIuSUhpc3RvcnlPYmplY3QDAAAABl9pdGVtcwVfc2l6ZQhf
        dmVyc2lvbgQAAC1BRE1TX0Rlc2t0b3AuRG9jdW1lbnRNYW5hZ2VyLklIaXN0b3J5T2JqZWN0W10DAAAA
        CAgCAAAACQQAAAAAAAAAAAAAAAcEAAAAAAEAAAAAAAAABCtBRE1TX0Rlc2t0b3AuRG9jdW1lbnRNYW5h
        Z2VyLklIaXN0b3J5T2JqZWN0AwAAAAs=
    </value>
  </data>

这是从此控件添加到 .resx 文件的唯一属性,如果我删除此添加的数据部分,应用程序构建并运行得很好.

This is the only property that is added to the .resx file from this control and if I delete this added data section, the app builds and runs just fine.

此问题在两台不同的机器和两个不同的用户上的 Visual Studio 2012 和 2013 中都发生.损坏的 .resx 文件不会阻止设计器中的任何内容正常工作.有没有人知道可能导致这种情况的原因?我已经为下面的 HistoryList 的所有属性添加了签名.

This problem is occurring in both Visual Studio 2012 and 2013 on two different machines, and two different users. The broken .resx file does not prevent anything in the designer from working properly. Does anyone have an idea of what might be causing this? I've add the signatures for all the properties of HistoryList below.

历史列表:

Public Property HistoryList As List(Of IHistoryObject)

IHistoryObject:

IHistoryObject:

Public Interface IHistoryObject
    Property FolderList As List(Of IFolder)
    Property DocumentList As List(Of IDocument)
    Property DefaultHandler As IDocumentHandler
    Property FolderName As String
End Interface

文件夹:

Public Interface IFolder
    Property FolderName() As String
    Property SubFolders() As List(Of IFolder)
    Property Documents() As List(Of IDocument)
    Property DefaultDocumentHandler() As IDocumentHandler
End Interface

IDocument:

Public Interface IDocument
    Property DocumentName() As String
    Property DocumentType() As DocumentType
    Property DocumentLocation() As DocumentLocation
    Property ScreenLocation() As ScreenLocation
    Property DocumentIdentifier() As String
    Property Compressed() As Boolean
    Property DocumentHandler() As IDocumentHandler
    Property UsedDocumentId() As Integer
    Property PrivateDocument() As Boolean
    Property SavedDate() As DateTime
    Property KnowledgeLakeDocumentTypeId() As Integer?
    Property KnowledgeLakeDocumentClassId() As Integer?
    Property RequiresFollowUp() As Boolean
    Property Comments() As String
    Property DevelopmentKey() As Integer
    Property Version() As Integer
    Property MonitoringId() As Integer?
    Property FollowUpDate() As Date?
    Property FollowUpUsers As List(Of Integer)
End Interface

IDocumentHandler:

IDocumentHandler:

Public Interface IDocumentHandler
    Sub Open(document As IDocument)
    Sub OpenVersion(sourceTableId As Integer, fileName As String)
    Function Delete(document As IDocument, Optional saveHistory As Boolean = True) As DocumentAddReturnData
    Sub SaveToDisk(document As IDocument, filePath As String, openWhenDone As Boolean)
    Function Add(documentBinary As Byte(), ByRef document As IDocument) As DocumentAddReturnData
    Function Replace(existingDocument As IDocument, newDocument As Byte(), fileName As String) As DocumentAddReturnData
    Function Replace(documentId As Integer, newDocument As Byte()) As DocumentAddReturnData
    Function FileNameExists(fileName As String, Optional developmentKey As Integer = 0, Optional monitoringKey As Integer = 0) As DocumentConstants.FileNameExists
    Function FilePathExists(filePath As String, Optional developmentKey As Integer = 0, Optional monitoringKey As Integer = 0) As DocumentConstants.FileNameExists
    Function AppendFileNumber(fileName As String, Optional developmentKey As Integer = 0, Optional monitoringKey As Integer = 0) As String
End Interface

推荐答案

版本=4.0.5207.25065

Version=4.0.5207.25065

这就是导致错误的原因.您让包含 DocumentManager.IHistoryObject 实现类型的程序集的 [AssemblyVersion] 属性自动递增.它看起来类似于 AssemblyInfo.vb 源文件中的 .因此,每次重建时,程序集都会获得不同的版本号.这会对序列化数据造成严重破坏,它仍然包含使用原始版本号序列化的数据.因此不再兼容.设计器在尝试反序列化 .resx 文件中的数据时失败.

This is what causes the error. You are letting the [AssemblyVersion] attribute of the assembly that contains the DocumentManager.IHistoryObject implementation type automatically increment. It would look similar to <Assembly: AssemblyVersion("4.0.*")> in the AssemblyInfo.vb source file. So every time you rebuild, the assembly gets a different version number. This plays havoc on the serialized data, it still contains the data that was serialized with the original version number. And is therefore not compatible anymore. The designer falls over when it tries to deserialize the data in .resx file.

因此,如果您打算保留 .resx 文件,那么您需要禁用此自动递增功能.然而,这听起来像是偶然的,您实际上根本不希望这种情况发生.使用 DesignMode 属性测试是一种解决方法,但它不是正确的方法.您只需告诉设计人员从不保留数据.你用一个属性来做到这一点:

So if you intend to keep the .resx file then you'll need to disable this auto-incrementing. It however sounds like this was accidental and you don't actually want this to happen at all. Using the DesignMode property test is a workaround but it is not the correct one. You simple tell the designer to never persist the data. You do so with an attribute:

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    <Browsable(False)> _
    Public Property History As List(Of IHistoryObject)

[Browsable] 属性还可以防止您在属性"窗口中编辑属性时发生意外.

The [Browsable] attribute also prevents accidents when you edit the property in the Properties window.

这篇关于Visual Studio 错误地将数据添加到 Resx 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆