machine / machine.specifications

Machine.Specifications is a Context/Specification framework for .NET that removes language noise and simplifies tests.
MIT License
885 stars 178 forks source link

System.FieldAccessException: Cannot set a constant field #351

Closed toebens closed 5 years ago

toebens commented 6 years ago

Hi, we upgraded our spec project's packages config to use the latest machine specification packages. We had upgraded from:

`

`

to: `

`

Skipped the packages we did not upgrade.

Now we are getting tons of messages when running the tests:

Fatal Error System.FieldAccessException: Cannot set a constant field. at System.Reflection.MdFieldInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) at Machine.Fakes.Sdk.ReflectionExtensions.<>c__DisplayClass7_0.<ResetReferences>b__1(FieldInfo x) at Machine.Fakes.Sdk.MissingFrameworkExtensions.Each[T](IEnumerable1 enumerable, Action1 action) at System.Collections.Generic.List1.ForEach(Action1 action) at Machine.Fakes.Internal.BehaviorConfigController.CleanUp(Object subject) at Machine.Fakes.WithFakes2.<>c.<.ctor>b__1_0() `

What's wrong? How can i identify where the problem might be? What is causing these exceptions?

Please note that we switched the project from net45 to net 471 some weeks back and hadn't had the problem. We did not update the packages. However i suppose it is some because of the new Machine.Fakes version. Thanks, toebens

robertcoltheart commented 5 years ago

Can you please provide some sample code that reproduces the above?

toebens commented 2 years ago

It seems that a public const property within a behavior configuration class is causing these issues. I moved the constant properties to another class then the error is gone.