Skip to content
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

Could not load file or assembly Microsoft.DotNet.PlatformAbstractions under dotnet tye #466

Closed
staff0rd opened this issue Apr 13, 2020 · 9 comments · Fixed by #480
Closed
Assignees

Comments

@staff0rd
Copy link

I see the following in logs for an azure-pipeline job for a dotnet core 3.1 application. These lines appear in the tye step of this pipeline.

Regardless of this error, the versions still seem to be updated correctly, for both the pipeline, dotnet assembly and node script. As such I post this here for informative purposes only.

2020-04-13T05:26:25.9406642Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
2020-04-13T05:26:25.9408785Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
2020-04-13T05:26:25.9410785Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:  ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKey***=adb9793829ddae60'. The system cannot find the file specified.
2020-04-13T05:26:25.9412046Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: 
2020-04-13T05:26:25.9413899Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: File name: 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKey***=adb9793829ddae60'
2020-04-13T05:26:25.9415112Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitLoaderContext.GetNativeLibraryDirectory()
2020-04-13T05:26:25.9416177Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitLoaderContext.LoadUnmanagedDll(String unmanagedDllName)
2020-04-13T05:26:25.9417326Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext)
2020-04-13T05:26:25.9418454Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
2020-04-13T05:26:25.9419623Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary()
2020-04-13T05:26:25.9420629Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods..cctor()
2020-04-13T05:26:25.9421673Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: 
2020-04-13T05:26:25.9422629Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018: 
2020-04-13T05:26:25.9423869Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    --- End of inner exception stack trace ---
2020-04-13T05:26:25.9424971Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.git_libgit2_opts(Int32 option, UInt32 level, String path)
2020-04-13T05:26:25.9426094Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.Proxy.git_libgit2_opts_set_search_path(ConfigurationLevel level, String path)
2020-04-13T05:26:25.9427226Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths)
2020-04-13T05:26:25.9428371Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo, Boolean useDefaultConfigSearchPaths)
2020-04-13T05:26:25.9429732Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot)
2020-04-13T05:26:25.9430984Z /home/vsts/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner()
2020-04-13T05:26:25.9431677Z     0 Warning(s)
2020-04-13T05:26:25.9432033Z     1 Error(s)
@AArnott
Copy link
Collaborator

AArnott commented Apr 13, 2020

Thanks for sharing. I'm unfamiliar with Tye, and can only guess that as part of running it, it executes some part of your msbuild projects (again) but in some environment that isn't what we are prepared for.

For this to be actionable, can you provide the OS of the agent, including version?

@staff0rd
Copy link
Author

Is this enough? ubuntu-16.04

@AArnott
Copy link
Collaborator

AArnott commented Apr 16, 2020

I'm afraid when I try on ubuntu 16.04 it works. And you reported it works too, except under dotnet tye, which I'm unfamiliar with. So while I thank you for reporting it, I don't think I'll spend more time on it, at least without more reports.

@AArnott AArnott changed the title Could not load file or assembly Microsoft.DotNet.PlatformAbstractions Could not load file or assembly Microsoft.DotNet.PlatformAbstractions under dotnet tye Apr 16, 2020
@AArnott AArnott closed this as completed Apr 16, 2020
@yyjdelete
Copy link

@AArnott
Get the same exception when try lastest daily builds of net5.0 sdk, and seems Microsoft.DotNet.PlatformAbstractions is already removed and no longer be an part of lastest daily builds of net5.0 sdk.
dotnet/runtime#3470
dotnet/sdk#11076

@AArnott AArnott reopened this Apr 28, 2020
@eerhardt
Copy link
Member

I am working on removing the Microsoft.DotNet.PlatformAbstractions library. Before dotnet/sdk#11076, this library was implicitly loadable from MSBuild running on .NET Core. This was because the assembly was shipping in the dotnet\sdk\<version> directory. After dotnet/sdk#11076, the .NET 5.0 SDK no longer ships PlatformAbstractions with it.

So if your task relies on PlatformAbstractions, you will need to package the assembly with your task assembly (just like any other 3rd party library).

Alternatively, an API to get the current machine's RID was added to .NET 5 with RuntimeInformation.RuntimeIdentifier. However, it is only available on .NET 5, and not previous versions of .NET Core, nor on .NET Framework.

@eerhardt
Copy link
Member

I just looked where you are using RuntimeEnvironment.GetRuntimeIdentifier() in this project.

internal static string GetNativeLibraryDirectory()
{
var dir = Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location);
return Path.Combine(dir, RuntimePath, RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
}

Another alternative that is available in .NET Core 3.0+ is to use the new System.Runtime.Loader.AssemblyDependencyResolver class. Check out https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support for more information.

Basically, the idea is that you ship a .deps.json file next to your assembly, along with the runtimes\<RID> folders, and AssemblyDependencyResolver will do the RID fallback for you. This could help you get rid of the RuntimeIdMap code as well.

@clairernovotny
Copy link
Member

clairernovotny commented May 20, 2020

This just broke me locally on Windows with dotnet build using the 5.0p4 SDK.

C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:  ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: File name: 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitLoaderContext.GetNativeLibraryDirectory() [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitLoaderContext.LoadUnmanagedDll(String unmanagedDllName) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.git_libgit2_init() [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary() [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods..cctor() [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    --- End of inner exception stack trace --- [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.NativeMethods.git_libgit2_opts(Int32 option, UInt32 level, String path) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.Proxy.git_libgit2_opts_set_search_path(ConfigurationLevel level, String path) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo, Boolean useDefaultConfigSearchPaths) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
C:\Users\Claire\.nuget\packages\nerdbank.gitversioning\3.1.91\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() [D:\dev\NuGetPackageExplorer\Types\Types.csproj]
    0 Warning(s)
    1 Error(s)

@AArnott
Copy link
Collaborator

AArnott commented May 20, 2020

Can someone who was hit by this please verify the fix is effective by acquiring 2.3.7-beta from here:
https://dev.azure.com/andrewarnott/OSS/_packaging?_a=package&feed=PublicCI&package=Nerdbank.GitVersioning&protocolType=NuGet&version=3.2.7-beta&view=overview

@clairernovotny
Copy link
Member

Done, that fixed it for me

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

Successfully merging a pull request may close this issue.

5 participants