Can't find *.g.i.cs when using Code Contracts. RRS feed

  • Question

  • I'm trying to add contracts to an existing solution with many projects. One of the projects has a WPF resource dictionary in it. Now any project that references this project and has Static Checking turned on will create an error stating that it can't find the <resource dictionary>.g.i.cs file, even if it doesn't use this resource dictionary.

    Is there a work around for this?
    Tuesday, March 17, 2009 2:45 PM


  • The new release does include some fixes to issues with WPF builds. Please give it a try and let us know if the problem persists on your side.

    Cheers, -MaF (Manuel Fahndrich)
    Tuesday, April 21, 2009 8:58 PM

All replies

  • Hi Josh,

    I'm sorry for the problem. I'm currently debugging the WPF msbuild process. Something is broken, but it isn't clear what yet. One workaround that might solve your issue is to reference Microsoft.Contracts.dll from the WPF projects, even if they don't use contracts directly. Let me know.
    Cheers, -MaF (Manuel Fahndrich)
    Tuesday, March 17, 2009 11:19 PM
  • Hi Josh, thanks for sending me the repro. I noticed that the problem seems to be intermittent. If I rebuild, it seems to work. I'll see what I can do about it.
    Cheers, -MaF (Manuel Fahndrich)
    Wednesday, March 18, 2009 6:25 PM
  • The new release does include some fixes to issues with WPF builds. Please give it a try and let us know if the problem persists on your side.

    Cheers, -MaF (Manuel Fahndrich)
    Tuesday, April 21, 2009 8:58 PM
  • The problem still occurs in the following scenario:

    A solution contains 3 projects all of which reference Microsoft.Contracts


    MainApp references  UILibrary1 and UILibrary2
    UILibrary2 references UILibrary1
    UILibrary1 doesn't reference any other project

    UILibrary1 contains a single WPF window:  Window2
    UILibrary2 is empty , it  contains no code or xaml

    Without code contracts this builds. With code contracts on, I get these errors:

    ...\Window2.g.i.cs' could not be found 
    ...\GeneratedInternalTypeHelper.g.i.cs' could not be found

    If I remove the dependency of MainApp on UILibrary2 everything works

    I have available the minimal solution that reproduces the problem.


    • Edited by bankoh Wednesday, June 24, 2009 7:41 PM
    Wednesday, June 24, 2009 7:39 PM
  • Hi,

    Any workarounds for this yet?

    I'm currently experiencing the same issue with the latest version of Code Contracts, downloaded from MS dev labs.  I'm using Visual Studio 2008 Standard SP1.

    This issue even occurs if I disable runtime checking in my projects.  Note that because I'm only using VS Standard edition, I can't enable static checking.  So even without any checking enabled, I still can't build my solution.

    It appears that the only fix is to remove the references to the Microsoft.CodeContracts.dll assembly from all of my projects.


    Monday, September 28, 2009 5:26 AM
  • I'm experiencing this issue as well.  My scenario is similar to the one mentioned above.  I have three projects, all of which reference Microsoft.Contracts:

    MainApp - WPF application
    UILibrary - WPF control library
    Library - Basic .Net class library (non-WPF)

    MainApp references UILibrary and Library.
    Neither UILibrary nor Library reference each other.

    As stated above, the only solution appears to be to remove Code Contracts from all projects.
    Wednesday, October 14, 2009 9:01 PM
  • Ok... I found a temporary workaround.  The error message says that it can't find these *.g.i.cs files, so I just created a pre-build event that creates them.  It does this by just copying a blank dummy file that I created in the solution root directory. The files are blank, so they don't affect the compilation or rewritten code at all, yet they satisfy the tool and successfully bypass the error message.

    Here is my pre-build event:

    copy "$(SolutionDir)Dummy.cs" "$(SolutionDir)UILibrary\obj\Debug\GeneratedInternalTypeHelper.g.i.cs"
    copy "$(SolutionDir)Dummy.cs" "$(SolutionDir)UILibrary\obj\Debug\ResourceDictionary.g.i.cs"
    copy "$(SolutionDir)Dummy.cs" "$(SolutionDir)UILibrary\obj\Debug\Themes\Generic.g.i.cs"
    Wednesday, October 14, 2009 10:35 PM
  • Since this thread shows as already being answered, I decided to post a repro and workaround steps on a different thread.  You can get to it here:


    Friday, October 16, 2009 9:09 PM
  • Thanks for the detailed info. I need to see if I can get someone from the WPF team to look at this.
    Cheers, -MaF (Manuel Fahndrich)
    Friday, October 16, 2009 10:51 PM
  • Thanks, I can repro it now!

    Cheers, -MaF (Manuel Fahndrich)
    Friday, October 16, 2009 10:59 PM
  • Okay, I found this:  http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f1577cfe-20b9-4c76-a5d3-bfaa5f6f9592/

    Turns out the problem is that the files are generated for the C# normal build and then removed, which means that when we get to build our contract reference assembly, the files are gone. I will figure out a work-around.
    Cheers, -MaF (Manuel Fahndrich)
    • Proposed as answer by Dave Sexton Friday, October 16, 2009 11:34 PM
    Friday, October 16, 2009 11:11 PM
  • Thanks Manuel and BigstickCarpet for following up with this issue.  I'm pleased to hear that it's been resolved.

    "*.g.i.cs could not be found" - Bug repro and workaround

    - Dave
    Tuesday, October 20, 2009 2:29 PM
  • Let me know if the new release 1.2.21022.12 actually fixes these problems for all of you. It did for the repro I tested it on.

    Cheers, -MaF (Manuel Fahndrich)
    Friday, October 23, 2009 3:28 AM