-
Notifications
You must be signed in to change notification settings - Fork 94
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
Generator may fail with "Could not load file or assembly 'YamlDotNet..." #221
Comments
I could use
|
@AraHaan If you are using .NET 5+, you should be using https://docs.microsoft.com/en-us/dotnet/api/system.environment.processid. |
I use the .NET 6 SDK but on that project I target |
It also seems to do it with |
Hmm it does it on every Windows API function when targeting .NET Standard 2.0. Edit: even the enums fail too... |
@AArnott Any idea why it wont at least let the generations of the enums when using the SourceGenerator on I at least need the source generator to maintain the values of a specific enum despite targeting netstandard2.0. |
Also I feel like the warning it prints should have included the stack trace of the exception that caused the |
What version of CsWin32 are you using, @AraHaan? With the latest CI version, this doesn't repro for me. |
It doesn't repro for me on 0.1.422-beta (latest on nuget.org) either. |
Could this be a result of combining a particular version of win32metadata? |
@jnm2 potentially yes. We only support using CsWin32 with the metadata that it brings in automatically, because the metadata churns so much right now. Updating metadata on your own is taking on risk that things break. |
Ok, I have simplified the reproducibility of this issue down to clone Also, I use the default one now, even with non default it still would get this error, and I tried every build of CsWin32 that was released to nuget.org with the same issue. |
I decided I wanted to test it on github actions using |
I tested locally a change and still could not fix it on my end. |
I can repro the exception to generate |
This prevents the whole generator from failing to generate anything when something goes wrong. Closes #221
Well, the repro I'm seeing is unlikely to be related to what you were seeing, since it's a new failure from #270. But I have a PR to improve the experience either way so we can better diagnose such failures in the future. |
I tried copiling again with |
The |
Currently it is reproducible with |
Great. With those repro steps I can see this error with the latest CsWin32 version:
So this may be a duplicate of #261, which is probably not completely fixed. YamlDotNet 11.0.0.0 is certainly included in the package, so it is probably some dependency whose assembly version is not precisely satisfied. |
Ok, by using a debugger I found that YamlDotNet.dll has already been loaded from %userprofile%.nuget\packages\securitycodescan.vs2019\5.1.0\analyzers\dotnet\YamlDotNet.dll I don't know what securitycodescan.vs2019 is, but this package includes YamlDotNet v8.1.2.0 which loads first and therefore causes .NET Core to be unwilling to load the 11.0.0.0 used by CsWin32 later in the build. I am concerned however at the lack of isolation between analyzers that the C# compiler IMO ought to be providing so that one analyzer's dependencies does not cause problems for another's dependencies. I'll follow up with the Roslyn team on this. |
@AraHaan, when I remove <PackageReference Include="SecurityCodeScan.VS2019" IsImplicitlyDefined="true" Version="*-*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> from your Sdk.props file, the CsWin32 error goes away (and is replaced by others that appear unrelated). I don't know if dropping that dependency for now is an option for you though. I've already reached out to the Roslyn team to ask for recommendations. |
Thanks so the issue is a combination of things. Wonder what other Analyzers that I use use a different version of |
Hey @AArnott, I'm interested in hearing what is the take of the Roslyn team on it. Is there a link? Is it public issue? |
Here is what I heard back from the Roslyn team:
|
Is that this issue? dotnet/roslyn#52177 |
It looks like it. |
Does |
I tried that and this was the result:
|
Hmm I wonder if all analyzers should start doing binding redirects of all of their dependencies from |
@JarLob |
It isn't parallelism that breaks it. It may simply be a build ordering issue. And it's super complex for the roslyn team to fix. It's not likely something we can totally workaround within the source generator, although we may be able to improve some scenarios. |
The roslyn issue tracking it is dotnet/roslyn#53672 |
I'm blocked by this myself in dotnet/Nerdbank.GitVersioning#616. |
@AArnott what if the part of the generator that uses YamlDotNet was split into a console program that the generator ships with and somehow is able to execute in a subprocess of the compiler to work around this? Is it possible to do that and permanently fix the YamlDotNet issue for now? |
We use |
We did indeed drop the YamlDotNet dependency. |
Nice |
Bumps [powershell](https://github.com/PowerShell/PowerShell) from 7.3.7 to 7.3.8. - [Release notes](https://github.com/PowerShell/PowerShell/releases) - [Commits](PowerShell/PowerShell@v7.3.7...v7.3.8) --- updated-dependencies: - dependency-name: powershell dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Currently for some reason the source generator starts to bail out when it sees
GetCurrentProcess
when called inside ofdotnet build
.Oddly it seems to generate just fine from within Visual Studio even if I use the .NET 6 Preview 1/2 SDK's.
This happens with my project with the following
NativeMethods.txt
:The first 2 is used when calling
MiniDumpWriteDump
and the 3rd one is for when constructing theEXCEPTION_INFORMATION
structure for the call.and the following
NativeMethods.json
file:The text was updated successfully, but these errors were encountered: