Skip to content

[Xamarin.Android.Build.Tasks] Crash - NetStandard library - could not load assembly during startup registration. #706

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
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TEST_APK_PROJECTS = \
# Syntax: $(call BUILD_TEST_APK,path/to/project.csproj)
define BUILD_TEST_APK
# Must use xabuild to ensure correct assemblies are resolved
MSBUILD="$(MSBUILD)" tools/scripts/xabuild /t:SignAndroidPackage $(1)
MSBUILD="$(MSBUILD)" tools/scripts/xabuild $(MSBUILD_FLAGS) /t:SignAndroidPackage $(1)
endef # BUILD_TEST_APK

run-apk-tests:
Expand Down
7 changes: 7 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ private void AddAssemblies (ZipArchiveEx apk)

int count = 0;
foreach (ITaskItem assembly in ResolvedUserAssemblies) {

if (MonoAndroidHelper.IsReferenceAssembly (assembly.ItemSpec)) {
Log.LogWarning ($"{assembly.ItemSpec} is a reference assembly!");
}
// Add assembly
apk.Archive.AddFile (assembly.ItemSpec, GetTargetDirectory (assembly.ItemSpec) + "/" + Path.GetFileName (assembly.ItemSpec), compressionMethod: CompressionMethod.Store);

Expand Down Expand Up @@ -305,6 +309,9 @@ private void AddAssemblies (ZipArchiveEx apk)
count = 0;
// Add framework assemblies
foreach (ITaskItem assembly in ResolvedFrameworkAssemblies) {
if (MonoAndroidHelper.IsReferenceAssembly (assembly.ItemSpec)) {
Log.LogWarning ($"{assembly.ItemSpec} is a reference assembly!");
}
apk.Archive.AddFile (assembly.ItemSpec, "assemblies/" + Path.GetFileName (assembly.ItemSpec), compressionMethod: CompressionMethod.Store);
var config = Path.ChangeExtension (assembly.ItemSpec, "dll.config");
AddAssemblyConfigEntry (apk, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Mono.Security.Cryptography;
using Xamarin.Android.Build.Utilities;
using Xamarin.Tools.Zip;
using Mono.Cecil;

#if MSBUILD
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -286,6 +287,14 @@ public static bool IsFrameworkAssembly (string assembly, bool checkSdkPath)
return TargetFrameworkDirectories == null || !checkSdkPath ? false : ExistsInFrameworkPath (assembly);
}

public static bool IsReferenceAssembly (string assembly)
{
var a = AssemblyDefinition.ReadAssembly (assembly, new ReaderParameters() { InMemory = true, ReadSymbols = false, });
if (!a.HasCustomAttributes)
return false;
return a.CustomAttributes.Any (t => t.AttributeType.FullName == "System.Runtime.CompilerServices.ReferenceAssemblyAttribute");
}

public static bool ExistsInFrameworkPath (string assembly)
{
return TargetFrameworkDirectories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,11 @@ because xbuild doesn't support framework reference assemblies.
<Target Name="_ResolveAssemblies">
<!--- Remove the ImplicitlyExpandDesignTimeFacades assemblies. We have already build the app there are not required for packaging -->
<ItemGroup>
<FilteredAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades'" />
<FilteredAssemblies Include="%(ReferenceCopyLocalPaths.Identity)"
Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.DestinationSubDirectory)' == '' "/>
<!-- Fallback to @(ReferencePath) if @(ReferenceCopyLocalPaths) is empty. This is for xbuild support -->
<FilteredAssemblies Include="%(ReferencePath.Identity)"
Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '@(ReferenceCopyLocalPaths)' == '' "/>
</ItemGroup>
<!-- Find all the assemblies this app requires -->
<ResolveAssemblies
Expand Down