I'm working on a new project and I've noticed that Visual Studio 2015 doesn't offer a quick fix for when a reference to an assembly is missing but it can clearly tell me what I need to add. 馃槃
Actually, I've noticed this for a long time and didn't bother to make an issue about it, I've searched briefly and didn't find an issue about it even though I'm sure someone already beat me to it and this a duplication but nonetheless a duplication is better than making the assumption it exists.
I didn't install Visual Studio 15 yet so I'm not sure whether this feature exists there.
Can you provide an example of this?
@CyrusNajmabadi Sure.
So here is some piece of code in a unit test project:
[Scenario]
public void GetItem(ModelCollection<FakeModelWithKey> collection, FakeModelWithKey addedItem, FakeModelWithKey retrievedItem)
{
"Given a command model with a single item added to it"
.x(() => {
collection = new ModelCollection<FakeModelWithKey>();
addedItem = new FakeModelWithKey("SomeKey");
collection.Add(addedItem);
});
"When the added item is retrieved"
.x(() => retrievedItem = collection["SomeKey"]);
"Then the retrieved item should be equal to the added item"
.x(() => addedItem.Should().Be(retrievedItem));
}
I've removed System.Xml.Linq from the project for the purpose of this example so Visual Studio 2015 gives me red squiggles under addedItem.Should() with the following error message:
Error CS0012 The type 'XElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Odd, we have this feature just for that purpose:
https://github.com/dotnet/roslyn/blob/master/src/Features/CSharp/Portable/CodeFixes/AddMissingReference/CSharpAddMissingReferenceCodeFixProvider.cs
Can you try this out with VS15 Preview5, or RC, and let us know if you're still hitting this? If so, we'll likely have to dig in further to figure out what's going wrong.
@CyrusNajmabadi Don't have it currently installed but maybe it's a good time to do it! 馃槃
I'll do that soon and let you know, thanks for fast reply.
@CyrusNajmabadi Seems like it happens there too.
Can you provide a repro solution where this happens? I'd like to take a look. Thanks!
@CyrusNajmabadi Sure! there you go https://github.com/eyalsk/Yalla
Yup. I can definitely repro this. It looks like the code we have to handle this is pretty poor. Because the diagnostic doesn't contain useful information, we try to back-infer the problem by examining the code directly and using IErrorTypeSymbols. That's pretty hacky and brittle. I think we need a proper diagnostic from the compiler stating specifically which assembly identity is needed. Investigating further.
Most helpful comment
Yup. I can definitely repro this. It looks like the code we have to handle this is pretty poor. Because the diagnostic doesn't contain useful information, we try to back-infer the problem by examining the code directly and using IErrorTypeSymbols. That's pretty hacky and brittle. I think we need a proper diagnostic from the compiler stating specifically which assembly identity is needed. Investigating further.