Gotchas: Assembly Level Attributes in F#

Wednesday, October 13, 2010 – 8:45 AM

This 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.

  1. 5 Responses to “Gotchas: Assembly Level Attributes in F#”

  2. Hi,
    A simple () also works :)

    By Huw on Oct 19, 2010

  1. 4 Trackback(s)

  2. Oct 14, 2010: Dew Drop – October 14, 2010 | Alvin Ashcraft's Morning Dew
  3. Oct 15, 2010: The Morning Brew - Chris Alcock » The Morning Brew #708
  4. Nov 11, 2010: Good Directions 487P-6 6-Feet 4-Fish Copper Rain Chain, Polished Finish | Upstate Gutters Greenville SC (864) 809-8642
  5. Dec 27, 2010: Quick Gr1d F# Tips « Chris

Sorry, comments for this entry are closed at this time.