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.

Caching issues with ReadyToRun images

See original GitHub issue

ReadyToRun images from a previous build can currently be reused when they should not.

Here’s what contributes to the issue:

  • The _CreateR2RImages target compares file timestamps: as long as the input file has an earlier timestamp than the R2R file, the R2R file will not be regenerated.
  • NuGet uses the timestamps from the nupkg when restoring packages, which means files from a newly restored package will have an earlier timestamp. But changing that wouldn’t help much, as a given package can already be present in the package cache.
  • The Clean target does not clean the R2R images

This means that you will end up with an outdated R2R image if you update a NuGet package and then republish the project, unless you delete the obj directory manually first.

Here’s how to reproduce this:

dotnet new console
dotnet add package Newtonsoft.Json -v 11.0.2
dotnet publish -r win-x64 -p:PublishReadyToRun=true
dotnet add package Newtonsoft.Json -v 12.0.3
dotnet publish -r win-x64 -p:PublishReadyToRun=true

The Newtonsoft.Json.dll in the publish output will be the v11.0.2 version instead of v12.0.3. Inserting dotnet clean -r win-x64 after the first publish does not help.

To recap, I see two issues:

  • R2R images should be invalidated when the source assembly is modified, using something stronger than just the file timestamp
  • The Clean target should delete the R2R images

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

3reactions
ltrzesniewskicommented, Oct 28, 2020

Here’s a workaround I’m using, maybe it can help you too:

<!-- Work around https://github.com/dotnet/sdk/issues/12379 -->
<Target Name="DeleteR2RImages" BeforeTargets="_PrepareForReadyToRunCompilation" Condition="'$(PublishReadyToRun)' == 'true'">
  <PropertyGroup>
    <_R2RDirToRemove>$(IntermediateOutputPath)R2R</_R2RDirToRemove>
  </PropertyGroup>
  <RemoveDir Directories="$(_R2RDirToRemove)" />
</Target>

This basically clears the R2R cache before each publish, so it’s not great, but it’s still better than getting a broken build.

It works on the 3.1 SDK. I haven’t tested it on .NET 5 yet but from a quick glance at the source, it should still work.

0reactions
kostazolcommented, Feb 10, 2022

The same problem was and exists in the old .Net Framework when I enable PrecompileBeforePublish - it publishes not a max version of NuGet packages, but these versions were used in another branch, and in VS I see the project used the previous versions of packages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conversation about ready to run - .NET Blog
What is the problem that ready to run solves. ... it should still run even though it would drop the R2R image and...
Read more >
readytorun-overview.md - dotnet/runtime
NGEN is fundamentally a cache (it is optional and only affects the performance of the app) and thus the fragility of the images...
Read more >
Building .NET Core AWS Lambda with ReadyToRun on ...
I decided to start from the two biggest problems: a big deployment package and a huge cold start. The Lambda function has been...
Read more >
dotnet publish command - .NET CLI
R2R is a form of ahead-of-time (AOT) compilation. For more information, see ReadyToRun images. To see warnings about missing dependencies that ...
Read more >
Caching Overview | Caching to improve performance
In order to maximize performance of Drupal, we need to understand Drupal's execution and caching model.
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