Use of volatile causes runtime MissingFieldException on rewritten assembly

Proposed Answer Use of volatile causes runtime MissingFieldException on rewritten assembly

  • mardi 29 novembre 2011 22:13
     
      A du code
    We recently came across an issue when using the volatile keyword and the rewriter.
    When not using the rewriter, everything worked fine, however when setting Perform Runtime Contract Checking to ReleaseRequires, a MissingFieldException was thrown when it came across the line of code accessing the field:
            private void DoTest()
            {
                Test.PerformingTest = true;
            }
    
    The exception is only thrown if the referenced field is in a separate assembly.
    namespace Library
    {
        public class Test
        {
            public static volatile bool PerformingTest;
        }
    }
    
    Removing the volatile keyword fixes the issue, but why would the rewriter cause this exception to be thrown?

Toutes les réponses

  • mardi 31 juillet 2012 15:40
     
     

    I have asked a very similar question on SO.  No answers there, either

    http://stackoverflow.com/q/11142908/90475


  • mercredi 1 août 2012 15:58
    Propriétaire
     
     
    Sorry about that! Are both assemblies being rewritten? Or just the one referencing the volatile field?

    Mike Barnett

  • dimanche 5 août 2012 15:02
    Propriétaire
     
     Réponse proposée
    I was able to reproduce the problem. The current rewriter doesn't preserve the required modifier on the type of the volatile field reference. At this point we are moving the rewriter to be based on top of a new infrastructure. I have verified that the new code does not display the same problem. We are close enough to releasing the new rewriter that we are not fixing any bugs in the old one. Unfortunately I do not have a firm date at which I can promise the new version, but it should be very soon.

    Mike Barnett


  • mercredi 24 avril 2013 21:15
    Propriétaire
     
     Réponse proposée

    I fixed this now. It will appear in the next release.


    Cheers, -MaF (Manuel Fahndrich)