c# - NodaTime with Fakes throws TypeInitializationException, but doesn't without Fakes -
i want shim nodatime systemclock.getcurrentinstant() method. therefore created unittest in visualstudio 2017 (also tried in 2015). added nodatime package through nuget package explorer unittest project. afterwards did right click on nodatime assembly , pressed add fakes assembly.
i wrote small piece of code, threw typeinitializationexception: common language runtime detected invalid program.
using microsoft.visualstudio.testtools.unittesting; using nodatime; namespace unittestproject1 { [testclass] public class unittest1 { [testmethod] public void testmethod1() { var = datetimezoneproviders.tzdb.getzoneornull("europe/amsterdam"); } } } this gave me following exception:
system.typeinitializationexception: type initializer 'tzdbholder' threw exception. ---> system.typeinitializationexception: type initializer 'defaultholder' threw exception. ---> system.invalidprogramexception: common language runtime detected invalid program. @ nodatime.timezones.tzdbzone1970location..ctor(int32 latitudeseconds, int32 longitudeseconds, ienumerable`1 countries, string zoneid, string comment) @ nodatime.timezones.tzdbzone1970location.read(idatetimezonereader reader) @ nodatime.timezones.io.tzdbstreamdata.builder.handlezone1970locationsfield(tzdbstreamfield field) @ nodatime.timezones.io.tzdbstreamdata.<>c.<.cctor>b__24_6(builder builder, tzdbstreamfield field) @ nodatime.timezones.io.tzdbstreamdata.fromstream(stream stream) @ nodatime.timezones.tzdbdatetimezonesource.defaultholder.loaddefaultdatasource() @ nodatime.timezones.tzdbdatetimezonesource.defaultholder..cctor() --- end of inner exception stack trace --- @ nodatime.timezones.tzdbdatetimezonesource.get_default() @ nodatime.datetimezoneproviders.tzdbholder..cctor() --- end of inner exception stack trace --- @ nodatime.datetimezoneproviders.get_tzdb() @ unittestproject1.unittest1.testmethod1() in c:\**snip**\unittestproject1\unittestproject1\unittest1.cs:line 16 i debugged nodatime source code , going bad on foreach loop on list. when removed foreach loop, code running fine. when added foreachloop on list of ints (see code below) exception came back.
foreach(var in list<int> {1,2,3}) {} when changed normal loop, exception disappeared.
var list = new list<int> {1,2,3}; for(var = 0; < list.count; i++) { var item = list[i]; } so has foreach loop , list. interested, code can found on nodatime's github repository
anyway, when remove fakes assembly generated @ beginning of post, test executes , passes. hey, wanted shim systemclock.getcurrentinstant() method mentioned earlier.
this not bug in nodatime, think bug in visualstudio test runner. google said 'no' when searched behavior of visual studio. tried run test nunit, succeeded, in nunit not possible use shimscontext :-(.
do guys know going on here? want check before report msft vs team.
thank helping me tracking down bug.
program versions:
- visual studio 15.2 (26430.15) release (enterprise edition)
- .net framework 4.7.02046
- fakes (latest shipped visual studio 15.2)
- windows 10 pro 64-bit (updated latest)
- resharper 2017.1.3 (tried without resharper enabled)
- nodatime 2.2.0 (latest stable nuget, tried compiling github repo)
Comments
Post a Comment