Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add contracts to System.Windows.Forms, System.Windows.Data classes #387

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Patashu
Copy link

@Patashu Patashu commented Feb 22, 2016

Just a bunch of contracts that I noticed were missing.

First pull request; LMK if I did anything wrong.

@Patashu
Copy link
Author

Patashu commented Feb 22, 2016

My pull request was denied due to many lines like

EXEC : error : Method System.Windows.Forms.DataGridViewRowCollection.AddInternal(System.Boolean, System.Object[]) exists only in contract reference assembly [C:\projects\codecontracts\Microsoft.Research\Contracts\System.Windows
.Forms\System.Windows.Forms10.csproj]

But in the system library, this method does exist:

internal int AddInternal(bool newRow, object[] values)
{
...
}

Can you explain what I am doing wrong/how to fix the problem?

@hubuk
Copy link
Contributor

hubuk commented Feb 22, 2016

@Patashu The problem is that you are specifying contracts for members which are inaccessible from outside of an assembly, i.e. internals and privates. For example internal int AddInternal(bool newRow, object[] values). This method is an internal method which can be accessed only by code contained in System.Windows.Forms.dll assembly. Defining contract for such method is of no use for consumers as they have no knowledge (other than reflection) of this method.

So, why the error mentions that the method exist only in contract reference assembly? It clearly exists also in System.Windows.Forms.dll but is not accessible.
That's correct, but the reason is that the check which reported the error is performed against a contract reference assembly and a reference assemblies contained in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework. These are assemblies which contains only externally visible members of an original framework assemblies and no code. You can check it in ILDasm.

So finally, to make your change work you need to remove all internal and private members/types from your code.

@Patashu
Copy link
Author

Patashu commented Feb 22, 2016

Good explanation, thanks. I'll fix it tomorrow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants