1

DLL に次のアセンブリ属性を定義しましたが、別のプロジェクトでそれを読み取ることができません。何か提案はありますか?

アセンブリ属性:

    Namespace Extensions.CustomAttributes

    <AttributeUsage(AttributeTargets.All, Inherited:=True, AllowMultiple:=True)>

    Public Class DeveloperNoteAttribute
        Inherits System.Attribute

        Protected strName, strComment As String
        Protected blnBug As Boolean

        Public Sub New(ByVal Name As String, ByVal Comment As String, ByVal DateRecorded As String)
            MyBase.New()
            strName = Name
            strComment = Comment
        End Sub

        Public Property Name As String
            Get
                Return strName
            End Get
            Set(ByVal value As String)
                strName = value
            End Set
        End Property

        Public Property Comment As String
            Get
                Return strComment
            End Get
            Set(ByVal value As String)
                strComment = value
            End Set
        End Property

        Public Property Bug As Boolean
            Get
                Return blnBug
            End Get
            Set(ByVal value As Boolean)
                blnBug = value
            End Set
        End Property

    End Class

End Namespace

AssemblyInfo.vb:

<Assembly: Extensions.CustomAttributes.DeveloperNoteAttribute("Test1", "Test2", "Test3")> 

別のプロジェクトの属性を取得します (変数: ファイル名を使用)

Dim oAssem As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(Filename)

' Get any assembly-level attributes
Dim oAttribs() As Attribute = Attribute.GetCustomAttributes(oAssem)
For Each att In oAttribs
   Try
        Dim at As Extensions.CustomAttributes.DeveloperNoteAttribute = CType(att, Extensions.CustomAttributes.DeveloperNoteAttribute)
        Debug.WriteLine(at.Name.ToString)
    Catch ex As Exception

    End Try
Next

デバッガーでは、「System.InvalidCastException」が大量に発生します

4

1 に答える 1