Reputation: 4940
I'm working in vb.NET (4.6.2), ASP.NET and VIsual Studio 2015.
This question is not about how to load attributes from an assembly. My sample code demonstrates that.
I have a web application ("foo") which references a DLL project in the same solution ("bar.dll").
The web application includes an "AssemblyVersionInfo.vb" file which is quote ordinary:
Imports System.Reflection
<Assembly: AssemblyProduct("Foo Product")>
<Assembly: AssemblyCompany("Foo Company")>
<Assembly: AssemblyCopyright("© Foo, Inc.")>
<Assembly: AssemblyTrademark("")>
<Assembly: AssemblyFileVersion("18.02.00")>
<Assembly: AssemblyVersion("18.02.00")>
The Bar.DLL project needs to access the version information, and tries to call it as such:
Dim asmbly As [Assembly] = [Assembly].GetExecutingAssembly
Dim tnProduct As AssemblyProductAttribute = System.Attribute.GetCustomAttribute(asmbly, GetType(AssemblyProductAttribute))
Dim tnCompany As AssemblyCompanyAttribute = System.Attribute.GetCustomAttribute(asmbly, GetType(AssemblyCompanyAttribute))
Dim tnCW As AssemblyCopyrightAttribute = System.Attribute.GetCustomAttribute(asmbly, GetType(AssemblyCopyrightAttribute))
Dim tnVersion As AssemblyFileVersionAttribute = System.Attribute.GetCustomAttribute(asmbly, GetType(AssemblyFileVersionAttribute))
Me.AppName = tnProduct.Product
Me.AppVersion = tnVersion.Version
Me.Copyright = tnCW.Copyright
Me.Company = tnCompany.Company
Here's my problem: At runtime, the "Me.AppName" line is throwing an "Object reference not set" exception. Stepping through in debug reveals that the tnProduct, tnVersion, tnCW and tnCompany objects are all Nothing.
So, I figured that the bar.dll project needed its own AssemblyVersionInfo.vb file. I added a copy of the AssemblyVersionInfo.vb file from the web project to the bar.dll project (both as a regular file and as a link), only to be greeted with a number of compile errors:
Attribute 'AssemblyCompanyAttribute' cannot be applied multiple times'
...and so on for each attribute.
What is the correct way to include an AssemblyVersionInfo.vb file in a solution so that its attributes are visible to all assemblies? Is there something obvious that I'm doing wrong?
Upvotes: 1
Views: 1261
Reputation: 4163
If you get this error that means this was already specified in another file. I don't know why but in VB this file is hidden from the developer. In C# it is in properties and it's called AssemblyInfo.cs
.
You can access it from the Properties->Application->Assembly information
page for the Bar
project and edit it there and set the value to empty string but you won't be able to delete the whole attribute completly from there.
So what you should do is to search for AssemblyProduct
. It should be found in both projects. Then go double-click the one item found in Bar
project. Now it should open the .vb file where you can see those attributes and just delete them.
Alternatively you can just go to files on disk and in My Project
folder there should a file with those attributes declared.
After that you can easily add your file as a link or normally.
Upvotes: 1