Gotchas: Assembly Level Attributes in F#
Wednesday, October 13, 2010 – 8:45 AMThis is something I discovered ages ago and should have been in my original Gotchas: Common Traps for the F# n00b post. I figured out how to add assembly level attributes to one of my F# assemblies but forgot to include it in the post.
The gotcha is that because F# projects don’t include a default AssemblyInfo.fs file you’re left to figure this out for yourself. If you do the obvious thing and just add the attribute (example in lines 9-13 below) you’ll see the following error:
This attribute is not valid for use on this language element. Assembly attributes should be attached to a ‘do ()’ declaration, if necessary within an F# module.
It turns out that the module needs an empty do() statement at the end of it. So your assemblyInfo.fs file might look something like this.
1: #light
2:
3: namespace NBody.DomainModel.Integrators
4:
5: open System
6: open System.Reflection;
7: open System.Runtime.InteropServices;
8:
9: [<assembly: AssemblyTitle("NBody.DomainModel.FSharp")>]
10: [<assembly: AssemblyDescription("F# integrators")>]
11:
12: [<assembly: ComVisible(false)>]
13: [<assembly: CLSCompliant(false)>]
14:
15: do()
Note the do() at line 15. Adding this fixes the problem and the code compiles.
5 Responses to “Gotchas: Assembly Level Attributes in F#”
Hi,
A simple () also works :)
By Huw on Oct 19, 2010