-
Notifications
You must be signed in to change notification settings - Fork 564
[Xamarin.Android.Build.Tasks] <ResolveAssemblies/> and ref assemblies #3053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dellis1972
merged 1 commit into
dotnet:master
from
jonathanpeppers:microsoft.extensions.http
May 1, 2019
Merged
[Xamarin.Android.Build.Tasks] <ResolveAssemblies/> and ref assemblies #3053
dellis1972
merged 1 commit into
dotnet:master
from
jonathanpeppers:microsoft.extensions.http
May 1, 2019
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes: dotnet#3045 In VS 2019 16.1 Preview, a project using `Microsoft.Extensions.Http` fails to build with: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2146,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'System.Runtime.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference) at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) at Mono.Cecil.TypeReference.Resolve() at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName) at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.BaseStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Temp\ResolveAssembliesSystemRuntime\AndroidApp1\AndroidApp1.csproj] The problem being, that the `<ResolveAssemblies/>` MSBuild task didn't return `System.Runtime.dll` in `@(ResolvedAssemblies)`. What further complicated matters, was that the same project was working with latest xamarin-android/master (16.2)? I was only able to reproduce the problem in a test after some work to create a project that only has a `<PackageReference/>` to ``Microsoft.Extensions.Http` with no other references *at all*. I had to do some MSBuild trickery to remove `Java.Interop` and `System.Runtime` references. Looking at the dependency tree in the failing test, `System.Runtime.CompilerServices.Unsafe.dll` should be reporting a reference to `System.Runtime.dll`. Through debugging, I saw it only had a reference to `netstandard.dll`? Then I realized there were two assemblies: ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll The "ref" assembly, references `netstandard.dll` and the "lib" assembly (that we should be using) references `System.Runtime.dll`. Through further debugging, I found two bugs here: * We shouldn't call `resolver.AddSearchDirectory` until *after* we've checked if the top-level assembly is a reference assembly. We don't want a reference assembly in the search paths! * `MetadataResolver` should key its cache on the resolved path to the assembly. This allows `<ResolveAssemblies/>` to open two *different* instances of `System.Runtime.CompilerServices.Unsafe`.
Member
Author
|
I'm off tomorrow, but when I'm back I want to test cherry-picking this to d16-1 and be sure the problem will be fixed there. /cc @brendanzagaeski |
dellis1972
approved these changes
May 1, 2019
Contributor
|
This look good. One test failure is not related to this PR, and one windows its the AOT stuff which is still failing. Again not related to this PR. |
jonathanpeppers
added a commit
to jonathanpeppers/xamarin-android
that referenced
this pull request
May 2, 2019
…dotnet#3053) Fixes: dotnet#3045 In VS 2019 16.1 Preview, a project using `Microsoft.Extensions.Http` fails to build with: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2146,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'System.Runtime.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference) at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) at Mono.Cecil.TypeReference.Resolve() at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName) at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.BaseStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Temp\ResolveAssembliesSystemRuntime\AndroidApp1\AndroidApp1.csproj] The problem being, that the `<ResolveAssemblies/>` MSBuild task didn't return `System.Runtime.dll` in `@(ResolvedAssemblies)`. What further complicated matters, was that the same project was working with latest xamarin-android/master (16.2)? I was only able to reproduce the problem in a test after some work to create a project that only has a `<PackageReference/>` to ``Microsoft.Extensions.Http` with no other references *at all*. I had to do some MSBuild trickery to remove `Java.Interop` and `System.Runtime` references. Looking at the dependency tree in the failing test, `System.Runtime.CompilerServices.Unsafe.dll` should be reporting a reference to `System.Runtime.dll`. Through debugging, I saw it only had a reference to `netstandard.dll`? Then I realized there were two assemblies: ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll The "ref" assembly, references `netstandard.dll` and the "lib" assembly (that we should be using) references `System.Runtime.dll`. Through further debugging, I found two bugs here: * We shouldn't call `resolver.AddSearchDirectory` until *after* we've checked if the top-level assembly is a reference assembly. We don't want a reference assembly in the search paths! * `MetadataResolver` should key its cache on the resolved path to the assembly. This allows `<ResolveAssemblies/>` to open two *different* instances of `System.Runtime.CompilerServices.Unsafe`.
jonpryor
pushed a commit
that referenced
this pull request
May 2, 2019
…#3053) (#3062) Fixes: #3045 In VS 2019 16.1 Preview, a project using `Microsoft.Extensions.Http` fails to build with: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2146,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'System.Runtime.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference) at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) at Mono.Cecil.TypeReference.Resolve() at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName) at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.BaseStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Temp\ResolveAssembliesSystemRuntime\AndroidApp1\AndroidApp1.csproj] The problem being that the `<ResolveAssemblies/>` MSBuild task didn't return `System.Runtime.dll` in `@(ResolvedAssemblies)`. What further complicated matters, was that the same project was working with latest xamarin-android/master (16.2)? I was only able to reproduce the problem in a test after some work to create a project that only has a `<PackageReference/>` to `Microsoft.Extensions.Http` with no other references *at all*. I had to do some MSBuild trickery to remove `Java.Interop` and `System.Runtime` references. Looking at the dependency tree in the failing test, `System.Runtime.CompilerServices.Unsafe.dll` should be reporting a reference to `System.Runtime.dll`. Through debugging, I saw it only had a reference to `netstandard.dll`? Then I realized there were two assemblies: ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll The "ref" assembly, references `netstandard.dll` and the "lib" assembly (that we should be using) references `System.Runtime.dll`. Through further debugging, I found two bugs here: * We shouldn't call `resolver.AddSearchDirectory()` until *after* we've checked if the top-level assembly is a reference assembly. We don't want a reference assembly in the search paths! * `MetadataResolver` should key its cache on the resolved path to the assembly. This allows `<ResolveAssemblies/>` to open two *different* instances of `System.Runtime.CompilerServices.Unsafe`.
jonathanpeppers
added a commit
that referenced
this pull request
May 3, 2019
…#3053) Fixes: #3045 In VS 2019 16.1 Preview, a project using `Microsoft.Extensions.Http` fails to build with: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2146,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'System.Runtime.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference) at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) at Mono.Cecil.TypeReference.Resolve() at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName) at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.BaseStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Temp\ResolveAssembliesSystemRuntime\AndroidApp1\AndroidApp1.csproj] The problem being, that the `<ResolveAssemblies/>` MSBuild task didn't return `System.Runtime.dll` in `@(ResolvedAssemblies)`. What further complicated matters, was that the same project was working with latest xamarin-android/master (16.2)? I was only able to reproduce the problem in a test after some work to create a project that only has a `<PackageReference/>` to ``Microsoft.Extensions.Http` with no other references *at all*. I had to do some MSBuild trickery to remove `Java.Interop` and `System.Runtime` references. Looking at the dependency tree in the failing test, `System.Runtime.CompilerServices.Unsafe.dll` should be reporting a reference to `System.Runtime.dll`. Through debugging, I saw it only had a reference to `netstandard.dll`? Then I realized there were two assemblies: ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll The "ref" assembly, references `netstandard.dll` and the "lib" assembly (that we should be using) references `System.Runtime.dll`. Through further debugging, I found two bugs here: * We shouldn't call `resolver.AddSearchDirectory` until *after* we've checked if the top-level assembly is a reference assembly. We don't want a reference assembly in the search paths! * `MetadataResolver` should key its cache on the resolved path to the assembly. This allows `<ResolveAssemblies/>` to open two *different* instances of `System.Runtime.CompilerServices.Unsafe`.
jonpryor
pushed a commit
that referenced
this pull request
May 3, 2019
…#3053) Fixes: #3045 In VS 2019 16.1 Preview, a project using `Microsoft.Extensions.Http` fails to build with: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2146,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'System.Runtime.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference) at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) at Mono.Cecil.TypeReference.Resolve() at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName) at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.BaseStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Temp\ResolveAssembliesSystemRuntime\AndroidApp1\AndroidApp1.csproj] The problem being, that the `<ResolveAssemblies/>` MSBuild task didn't return `System.Runtime.dll` in `@(ResolvedAssemblies)`. What further complicated matters, was that the same project was working with latest xamarin-android/master (16.2)? I was only able to reproduce the problem in a test after some work to create a project that only has a `<PackageReference/>` to ``Microsoft.Extensions.Http` with no other references *at all*. I had to do some MSBuild trickery to remove `Java.Interop` and `System.Runtime` references. Looking at the dependency tree in the failing test, `System.Runtime.CompilerServices.Unsafe.dll` should be reporting a reference to `System.Runtime.dll`. Through debugging, I saw it only had a reference to `netstandard.dll`? Then I realized there were two assemblies: ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll ~\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll The "ref" assembly, references `netstandard.dll` and the "lib" assembly (that we should be using) references `System.Runtime.dll`. Through further debugging, I found two bugs here: * We shouldn't call `resolver.AddSearchDirectory` until *after* we've checked if the top-level assembly is a reference assembly. We don't want a reference assembly in the search paths! * `MetadataResolver` should key its cache on the resolved path to the assembly. This allows `<ResolveAssemblies/>` to open two *different* instances of `System.Runtime.CompilerServices.Unsafe`.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #3045
In VS 2019 16.1 Preview, a project using
Microsoft.Extensions.Httpfails to build with:
The problem being, that the
<ResolveAssemblies/>MSBuild task didn'treturn
System.Runtime.dllin@(ResolvedAssemblies).What further complicated matters, was that the same project was
working with latest xamarin-android/master (16.2)? I was only able to
reproduce the problem in a test after some work to create a project
that only has a
<PackageReference/>toMicrosoft.Extensions.Httpwith no other references at all. I had to do some MSBuild trickery
to remove
Java.InteropandSystem.Runtimereferences.Looking at the dependency tree in the failing test,
System.Runtime.CompilerServices.Unsafe.dllshould be reporting areference to
System.Runtime.dll. Through debugging, I saw it onlyhad a reference to
netstandard.dll?Then I realized there were two assemblies:
The "ref" assembly, references
netstandard.dlland the "lib"assembly (that we should be using) references
System.Runtime.dll.Through further debugging, I found two bugs here:
resolver.AddSearchDirectoryuntil after we'vechecked if the top-level assembly is a reference assembly. We don't
want a reference assembly in the search paths!
MetadataResolvershould key its cache on the resolved path to theassembly. This allows
<ResolveAssemblies/>to open two differentinstances of
System.Runtime.CompilerServices.Unsafe.