tập tin AssemblyInfo.cs có thuộc tính AssemblyVersion, nhưng khi tôi chạy như sau:tại sao tôi không thể tải thuộc tính AssemblyVersion bằng cách sử dụng phản chiếu?
Attribute[] y = Assembly.GetExecutingAssembly().GetCustomAttributes();
tôi nhận được:
System.Runtime.InteropServices.ComVisibleAttribute
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
System.Runtime.CompilerServices.CompilationRelaxationsAttribute
System.Runtime.InteropServices.GuidAttribute
System.Diagnostics.DebuggableAttribute
System.Reflection.AssemblyTrademarkAttribute
System.Reflection.AssemblyCopyrightAttribute
System.Reflection.AssemblyCompanyAttribute
System.Reflection.AssemblyConfigurationAttribute
System.Reflection.AssemblyFileVersionAttribute
System.Reflection.AssemblyProductAttribute
System.Reflection.AssemblyDescriptionAttribute
nhưng tôi đã kiểm tra không biết bao nhiêu lần so với thuộc tính này hiện diện trong tôi mã:
[assembly: AssemblyVersion("5.5.5.5")]
... và nếu tôi cố gắng truy cập vào nó trực tiếp tôi nhận được một ngoại lệ:
Attribute x = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyVersionAttribute)); //exception
Tôi đoán tôi sẽ không thể sử dụng thuộc tính đó, nhưng tại sao .NET không đọc nó?
Bạn đang cố gắng làm gì? 'Assembly' đã có thuộc tính' Version'. – ashes999
bạn có chắc chắn không? Tôi thấy không phải là một tài sản tĩnh hoặc dụ với tên đó –
Bạn sẽ phải sử dụng 'GetName()' ví dụ 'var y = Assembly.GetExecutingAssembly(). GetName(). Version;' –