DevLabs > DevLabs Forums > Code Contracts > Code Contracts with ILMerge
Ask a questionAsk a question
 

AnswerCode Contracts with ILMerge

  • Thursday, September 10, 2009 9:13 AMmalignate Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    we are developing a framework which is seperated in about 3 Solutions and about 12 Projects. We hope this is just the beginning and dont want to reference hundreds of assemblies when using this framework.

    So the idea was to use ilmerge in our build process to make a single assembly and generate a contract assembly for this merged assembly. We use FinalBuilder for this stuff and it just works fine, but when adding a reference to the merged assembly we get and error:

    Error 1    Cannot extract contracts from rewritten assembly 'Hermes.Contracts'.    C:\Users\Sebastian\Desktop\ConsoleApplication1\ConsoleApplication1\EXEC    ConsoleApplication1

    We generate contract assemblies for each single project and I saw that the visual studio does not use the finally generated assembly in the binary path but a assembly somewhere in the debug folder:

    "C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrefgen" /pdb /out:"..\..\..\..\..\Binary\Hermes.Contracts.Endpoint.Contracts.dll" "obj\Debug\Decl\Hermes.Contracts.Endpoint.dll"

    Perhaps this is the difference that causes the error, but I dont understand it. I hope someboby can explain it to me, so I can create a working build process.
    •  

Answers

  • Tuesday, October 27, 2009 3:48 AMMike BarnettMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Seeing as I'm also the author of ILMerge, I would like to get to the bottom of this. If you can provide me with a (small) repro, then I'd be happy to look into it. Can you create a solution with just two projects in it that demonstrates the issue? Thanks! (And sorry for the problem.)

All Replies

  • Friday, September 18, 2009 4:05 PMManuel FahndrichMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

    Please make sure that the contract reference assemblies are never referenced explicitly by any projects or used as inputs to ILMerge. These contract reference assemblies are only there for looking up contracts by tools, such as the rewriter and the static checker, as well as the documentation generation.

    In order to get to the bottom of this, I would need to understand all your build steps in more detail and also what FinalBuilder is doing.


    Cheers, -MaF (Manuel Fahndrich)
  • Sunday, September 20, 2009 4:13 AMwizzard0 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm using ILMerge too, but experiencing a different error - at runtime, the assembly raises assertion 'Must use rewriter when using Contract.Requires'

    Maybe there's something wrong with the build order?

  • Friday, October 23, 2009 3:56 PMManuel FahndrichMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    This would indicate that you are ilmerging non-rewritten assemblies or that the rewriter isn't seeing some of the methods after ilmerging.

    Cheers, -MaF (Manuel Fahndrich)
  • Tuesday, October 27, 2009 3:48 AMMike BarnettMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Seeing as I'm also the author of ILMerge, I would like to get to the bottom of this. If you can provide me with a (small) repro, then I'd be happy to look into it. Can you create a solution with just two projects in it that demonstrates the issue? Thanks! (And sorry for the problem.)