question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ThrowExceptionForHR from an SDK task fails due to missing resource

See original GitHub issue

An MSBuild task in this repo that calls Marshal.ThrowExceptionForHR fails due to a missing resource assembly:

d:\sdk\artifacts\Debug\bin\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(308,5): error MSB4018: System.IO.FileNotFoundException: Could not load the specified file. [d:\sdk\artifacts\Debug\tmp\It_contains_r---AB2009D8\ResourceTest\ResourceTest.csproj]
d:\sdk\artifacts\Debug\bin\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(308,5): error MSB4018: File name: 'Microsoft.Build.Tasks.CodeAnalysis.resources' [d:\sdk\artifacts\Debug\tmp\It_contains_r---AB2009D8\ResourceTest\ResourceTest.csproj]
d:\sdk\artifacts\Debug\bin\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName) [d:\sdk\artifacts\Debug\tmp\It_contains_r---AB2009D8\ResourceTest\ResourceTest.csproj]
d:\sdk\artifacts\Debug\bin\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) [d:\sdk\artifacts\Debug\tmp\It_contains_r---AB2009D8\ResourceTest\ResourceTest.csproj]
d:\sdk\artifacts\Debug\bin\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) [d:\sdk\artifacts\Debug\tmp\It_contains_r---AB2009D8\ResourceTest\ResourceTest.csproj]

I’m not sure why this specific resource is needed by ThrowExceptionForHR. It looks like it may be caused by https://github.com/dotnet/roslyn/issues/26777.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nguerreracommented, May 20, 2019

This is fixed.

After merging master and accounting for test rename in command shown below, the appropriate exception is raised:

.dotnet\dotnet.exe test src\tests\Microsoft.NET.Build.Tests\Microsoft.NET.Build.Tests.csproj --filter "FullyQualifiedName=Microsoft.NET.Build.Tests.AppHostTests.AppHost_contains_resources_from_the_managed_dll"
D:\Src\sdk\artifacts\bin\Debug\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(328,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [D:\Src\sdk\artifacts\tmp\Debug\AppHost_conta---13435BED\ResourceTest\ResourceTest.csproj]
 D:\Src\sdk\artifacts\bin\Debug\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(328,5): error MSB4018: System.IO.DirectoryNotFoundException: The system cannot find the path specified. (0x80070003) [D:\Src\sdk\artifacts\tmp\Debug\AppHost_conta---13435BED\ResourceTest\ResourceTest.csproj]
 D:\Src\sdk\artifacts\bin\Debug\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(328,5): error MSB4018:    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) [D:\Src\sdk\artifacts\tmp\Debug\AppHost_conta---13435BED\ResourceTest\ResourceTest.csproj]
 D:\Src\sdk\artifacts\bin\Debug\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(328,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResourceUpdater.ThrowExceptionForLastWin32Error() in D:\Src\sdk\src\Tasks\Microsoft.NET.Build.Tasks\ResourceUpdater.cs:line 43
0reactions
nguerreracommented, Dec 14, 2018

That stack trace is very odd.

It is possible that latest Roslyn will fix this as the build task no longer does assembly resolve shenanigans. It might also change the symptom to something more decipherable. I will focus on that and then look at this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

missing resource exception - java
MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key Content Management Exception.
Read more >
IDisposable: What Your Mother Never Told You About ...
One difficulty of the IDisposable interface overcome with the Disposable Design Principle.
Read more >
MSBuild Error - SDKs missing
Hi, I'm setting up Bamboo for a .NET application. When I tried to perform MSBuild or Nuget restore task thru script, I get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found