AssemblyTitle' attribute in the .NET Framework
Your Product can comprise of several assemblies.
All of the assemblies will have a single product name and individual assemblies will have their own titles.
AssemblyProduct = "MyProduct"
AssemblyTitle = "MyProduct.Utilities"
and for another assembly
AssemblyTitle = "MyProduct.Security"
the assembly title is also used in the explorer file properties etc. File > Properties > Details
tab
File Description = AssemblyTitle
Product name = AssemblyProduct
Duplicate AssemblyVersion Attribute
I have also run into this issue in the past, so I am going to assume that your build process provides assembly information separately to providing versioning. And that causes a duplication as your project also has that info in the AssemblyInfo.cs
file. So remove the file and I think it should work.
c# - Get AssemblyTitle
I suspect that the issue is in code you have not shown: where you use the result of GetCustomAttributes()
. That's because Assembly.GetCustomAttributes(Type, bool)
in .Net Framework returns object[]
, while CustomAttributeExtensions.GetCustomAttributes(this Assembly, Type)
in .Net Core returns IEnumerable<Attribute>
.
So you need to modify your code accordingly. The simplest way would be to use .ToArray<object>()
, but a better solution might be to change your code so that it can work with IEnumerable<Attribute>
.
What are the best practices for using Assembly Attributes?
We're using a global file called GlobalAssemblyInfo.cs and a local one called AssemblyInfo.cs. The global file contains the following attributes:
[assembly: AssemblyProduct("Your Product Name")]
[assembly: AssemblyCompany("Your Company")]
[assembly: AssemblyCopyright("Copyright © 2008 ...")]
[assembly: AssemblyTrademark("Your Trademark - if applicable")]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif
[assembly: AssemblyVersion("This is set by build process")]
[assembly: AssemblyFileVersion("This is set by build process")]
The local AssemblyInfo.cs contains the following attributes:
[assembly: AssemblyTitle("Your assembly title")]
[assembly: AssemblyDescription("Your assembly description")]
[assembly: AssemblyCulture("The culture - if not neutral")]
[assembly: ComVisible(true/false)]
// unique id per assembly
[assembly: Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]
You can add the GlobalAssemblyInfo.cs using the following procedure:
- Select Add/Existing Item... in the context menu of the project
- Select GlobalAssemblyInfo.cs
- Expand the Add-Button by clicking on that little down-arrow on the right hand
- Select "Add As Link" in the buttons drop down list
Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute
This was spot on (Ian Kemp nos 1 above.) I was upgrading .net app to .net core 5, painful effort to rid this issue. Now all good.
Do a file search on your .net core app (I assume 3.X is the same) and remove all the AssemblyInfo.cs files (.net core builds AssembleyInfo from the project file so doesn't matter if you delete these as well.
Recompile and the problem should go away.
One extra, make sure your Library (DLL) files are all 'Library' in the Property group... e.g.
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net5.0</TargetFramework>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
How to read assembly attributes
This is reasonably easy. You have to use reflection. You need an instance of Assembly that represents the assembly with the attributes you want to read. An easy way of getting this is to do:
typeof(MyTypeInAssembly).Assembly
Then you can do this, for example:
object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
AssemblyProductAttribute attribute = null;
if (attributes.Length > 0)
{
attribute = attributes[0] as AssemblyProductAttribute;
}
Referencing attribute.Product
will now give you the value you passed to the attribute in your AssemblyInfo.cs. Of course, if the attribute you look for can occur more than once, you may get multiple instances in the array returned by GetCustomAttributes, but this is not usually an issue for assembly level attributes like the ones you hope to retrieve.
How do I get attributes from a .NET assembly that's referenced by a web project?
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.
Something like this:
Related Topics
Best Way to Iterate Folders and Subfolders
How to Allow an Anonymous User Access to Some Given Page in MVC
Does Ef Upsert Have to Be Done Manually
Change the Bordercolor of the Textbox
Printing a Formatted HTML Page in C#
Executing a Cygwin Process from .Net
How to Set PDF Paragraph or Font Line-Height with Itextsharp
C# Invalid Attempt to Call Read When Reader Is Closed
How to Pass Current User Information to All Layers in Ddd
ASP.NET MVC 4 + Ninject MVC 3 = No Parameterless Constructor Defined for This Object