Contract extraction and injection fails

Dec 5, 2010 at 10:52 PM

Hello, if you execute the following code you will loose some method bodies and contracts.

contractProvider = ContractHelper.ExtractContracts(host, module, pdbReader, pdbReader);
ContractHelper.InjectContractCalls(host, module, contractProvider, pdbReader);

contractProvider = ContractHelper.ExtractContracts(host, module, pdbReader, pdbReader);
ContractHelper.InjectContractCalls(host, module, contractProvider, pdbReader);

The problem is that when separate contracts from code a cast return null and a Dummy.MethodBody is returned instead (Line 887 of ContractHelper.cs).
After the first injection the type of the method body is changed to MutableCodeModel.SourceMethodBody and then when execute the second extraction the following cast fails:

var smb = sourceMethodBody as Microsoft.Cci.ILToCodeModel.SourceMethodBody;

I fix this by removing this apparently unnecesary cast. I test it and it's seems to work ok, but I don't know if this is the best solution.
I will upload a patch whit this fix.

Coordinator
Dec 8, 2010 at 5:46 PM

Thanks! I agree: the case does not seem necessary. And I can't remember why I put it in there in the first place. I have removed it. Good catch!