tom greene
tom greene

Reputation: 5449

g.i.cs file not found with WPF and code contracts

I have a WPF project which compiles just fine. However, when I enable code contracts, I get a lot of errors like the following:

file 'C:\MyProject\obj\Debug\MyFile.g.i.cs' could not be found

Is there workaround?

Upvotes: 2

Views: 1878

Answers (3)

James Messinger
James Messinger

Reputation: 3243

Just FYI... This bug has been fixed in the latest version of Code Contracts (v1.2.21023.14, released Oct. 22nd).

Upvotes: 1

James Messinger
James Messinger

Reputation: 3243

I posted a repro and workaround to this problem on the Code Contracts forum. Here's the URL:

http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/4f2af748-1db1-4175-abf0-fbcc82f177ee


The short answer is that the error occurs whenever you have multiple projects that reference each other in a Solution, and one of the child projects is a WPF control library. To get around the problem, you can either disable contract verification for the parent project(s) (the ones that reference the other projects), or you can add a post-build event to the offending child project(s) to create the *.g.i.cs files that the Code Contracts rewriter is looking for.

For example, create a blank text file in the root directory of your child project and name it "Blank.txt". Then add the following command as a post-build event in that project:

copy "$(ProjectDir)Blank.txt" "$(ProjectDir)obj\$(Configuration)\GeneratedInternalTypeHelper.g.i.cs"

Copy this line as many times as needed, one for each missing file.

Upvotes: 0

JaredPar
JaredPar

Reputation: 755317

Can you be a bit more specific about your repro steps? The significance of the files ending in .g.i.cs is they are files generated specifically to enable intellisense in running projects. They are not truly part of the build process and likely should not be consumed by code contracts. I'm not a code contracts expert by any means though so I could be wrong on this point.

Upvotes: 0

Related Questions