Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Fixes issue #6061 Add using writes the wrong reference down for a #6228

Merged
merged 6 commits into from Oct 16, 2018

Conversation

mkrueger
Copy link
Contributor

@mkrueger mkrueger commented Oct 8, 2018

framework assembly

@mkrueger
Copy link
Contributor Author

mkrueger commented Oct 8, 2018

I'm not sure in which use case this service is used - @Therzok can you provide one ?

The VS.NET implementation loads reflection assemblies and checks if the type exists - even if the name is null. I would really like to avoid that - looks like a double check. Roslyn has some way of discovering the type -> assembly name therefore I think this check assembly name -> type is not needed.

However if it is I would rather use cecil to look up the name - loading assemblies that way pollutes the app domain and loading may fail due to dependency/framework compatibility issues.

Any comments ?

@Therzok
Copy link
Contributor

Therzok commented Oct 9, 2018

I'm not sure in which use case this service is used - @Therzok can you provide one ?

There's 1 scenario that's fixed by this patch, and that's searching reference assemblies without having them referenced in any project. Saw it used in the codeaction, assumed that it was the fix. We currently have that toggled off, sorry for misdiagnosing.

To fix the bug report scenario, we need to normalize the references at MonoDevelop workspace level and change the path when we encounter a GAC assembly:
http://source.roslyn.io/#Microsoft.CodeAnalysis.Workspaces.MSBuild/MSBuild/ProjectFile/ProjectFile.cs,3a3a092b693fd0e7

My test project to repro the issue:
testusing.zip

Open testconsaddusing and trigger quickfix on MessageQueueInstaller. If that adds a relative reference to System.Messaging, the test should fail.

I've pushed a minor fixup to this branch, so the (currently) unused scenario is working

if (!(workspace.GetMonoProject (projectId) is DotNetProject monoProject))
return null;

string assemblyFile = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyLocation (assemblyName, monoProject.TargetFramework);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just use the assembly context from the project? That is, monoProject.AssemblyContext

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkrueger ping ^

Copy link
Contributor Author

@mkrueger mkrueger Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds reasonable - didn't know that projects have an assembly context. Just cnp that code from somewhere else in the IDE.

@slluis
Copy link
Member

slluis commented Oct 11, 2018

Can we have unit tests for this based on Marius' example?

@mkrueger
Copy link
Contributor Author

We can test the service however I don't know how this example should help - it's just using a quick fix. Better is to test such services directly there is no need for throwing quick fixes in they may change or get removed or something.

Roslyn is nothing we can control.

@slluis
Copy link
Member

slluis commented Oct 11, 2018

We just need to test that the service is properly integrated in VSMac. Up to you about using the example or not.

@slluis
Copy link
Member

slluis commented Oct 15, 2018

@Therzok can you please verify?

@Therzok
Copy link
Contributor

Therzok commented Oct 15, 2018

Issue is still not fixed, seeing relative path to /Library being written.

It seems like roslyn is not considering the assemblies as being reference assemblies, but like simple assembly references.

Trying to figure out what is causing them not to be seen as framework reference assemblies by Roslyn.

@Therzok
Copy link
Contributor

Therzok commented Oct 15, 2018

Discussed with roslyn folks: https://gitter.im/dotnet/roslyn?at=5bc4c2f2e65a634336e25bdf

Adding some code in workspace layer to handle this.

@Therzok
Copy link
Contributor

Therzok commented Oct 15, 2018

Currently working on adding tests. Two things don't work yet in this version:

  • net461 project referencing System.Messaging, on adding reference to net471, it doesn't correct it to a package assembly
  • gdk-sharp is a special case to handle. not sure how.

@Therzok
Copy link
Contributor

Therzok commented Oct 15, 2018

Added unit tests.

The one problem remaining is glib-sharp handling, as in, things which are in gac but not in a package.

I don't know how to solve that problem, especially without breaking AssemblyContext API or making it incredibly slow (IO + lots of allocations even on fast path).

@slluis
Copy link
Member

slluis commented Oct 16, 2018

@Therzok is the glib-sharp issue a big problem? In which cases things won't work?

@Therzok
Copy link
Contributor

Therzok commented Oct 16, 2018

It writes a relative path to /Library/Frameworks... for assemblies which are not included in a SystemPackage.

I'm not sure it's worth pursuing a fix for that, I've only seen glib-sharp, gtk# and co in there.

@slluis
Copy link
Member

slluis commented Oct 16, 2018

Ok then.

@slluis
Copy link
Member

slluis commented Oct 16, 2018

Let's resolve the conflicts and merge.

@Therzok
Copy link
Contributor

Therzok commented Oct 16, 2018

Rebased.

Copy link
Member

@DavidKarlas DavidKarlas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, maybe delete commented code.

@Therzok Therzok merged commit 7137ac5 into master Oct 16, 2018
@Therzok Therzok deleted the master-issue6061 branch October 16, 2018 18:03
@Therzok
Copy link
Contributor

Therzok commented Oct 16, 2018

@monojenkins backport release-7.7

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.

None yet

4 participants