我有一个名为DocumentExplorerControl的自定义用户控件,它有几个属性,其中一个叫做HistoryList。如果我对包含此控件的任何表单进行任何更改,则构建将失败并显示以下错误:
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文件中的问题:
<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文件的唯一属性,如果我删除此添加的数据部分,则应用程序构建并运行正常。
Visual Studio 2012和2013在两台不同的计算机和两个不同的用户上都出现此问题。损坏的.resx文件不会阻止设计器中的任何内容正常工作。有没有人知道可能导致这种情况的原因?我在下面添加了HistoryList的所有属性的签名。
HistoryList:
Public Property HistoryList As List(Of 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
的iFolder:
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:
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
答案 0 :(得分:3)
版本= 4.0.5207.25065
这是导致错误的原因。您将允许包含DocumentManager.IHistoryObject实现类型的程序集的[AssemblyVersion]属性自动递增。它看起来类似于AssemblyInfo.vb源文件中的<Assembly: AssemblyVersion("4.0.*")>
。因此,每次重建时,程序集都会获得不同的版本号。这会对序列化数据造成严重破坏,它仍然包含使用原始版本号序列化的数据。因此不再兼容。设计人员在尝试反序列化.resx文件中的数据时会失败。
因此,如果您打算保留.resx文件,那么您需要禁用此自动递增。然而,听起来这是偶然的,你实际上并不希望这种情况发生。使用DesignMode属性测试是一种解决方法,但它不是正确的。您只需告诉设计人员从不持久保存数据。您可以使用以下属性执行此操作:
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
<Browsable(False)> _
Public Property History As List(Of IHistoryObject)
[Browsable]属性还可以在“属性”窗口中编辑属性时防止发生意外。
答案 1 :(得分:0)
虽然HistoryList的签名没有初始化新集合,并且控件的构造函数没有初始化新的集合,但是从控件的load事件调用的函数确实初始化了一个新集合,所以我不得不使用{{1避免初始化。