mattjohnsonpint / TimeZoneConverter

Lightweight libraries to convert between IANA, Windows, Rails, and POSIX time zones.
Other
839 stars 81 forks source link

TypeInitializationException Could not load type 'System.Runtime.InteropServices.OSPlatform' from assembly 'mscorlib on DotNetCore 2.2 #39

Closed clmcgrath closed 5 years ago

clmcgrath commented 5 years ago

Doesn't seem to matter what i call i am getting a TypeInitializationException trying to load System.Runtime.InteropServices.OSPlatform

System.TypeInitializationException : The type initializer for 'TimeZoneConverter.TZConvert' threw an exception.
---- System.TypeLoadException : Could not load type 'System.Runtime.InteropServices.OSPlatform' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at TimeZoneConverter.TZConvert.TryWindowsToIana(String windowsTimeZoneId, String& ianaTimeZoneName)
   at DigitalParadox.EWS.SharedCalendar.Tests.ICSDateHelperTests.TimeZone_Resolves_From_Universal_ID(String timezoneId) in C:\Users\Chris McGrath\source\repos\DigitalParadox.EWS.CalendarSync\DigitalParadox.EWS.SharedCalendar.Tests\ICSDateHelperTests.cs:line 75
----- Inner Stack Trace -----
   at TimeZoneConverter.TZConvert..cctor()
jnyrup commented 5 years ago

Can you share a complete project hitting this issue? I tried compiling a .net core 2.2 project using TimeZoneConverter 2.5.1 and ran it on Windows 10. It didn't reproduce your issue.

second-string commented 5 years ago

I get the same issue but with System.Runtime.InteropServices.RuntimeInformation.dll. We've used this dll in our multi-project solution previously with no problems. Installing the TimeZoneConverter nuget upgraded it to the most recent nuget version (4.3.0), but then seems to complain about not being able to find the correct dll

Exception:
System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. 

Obviously not the exact same issue, but related. This is on a .NET Framework 4.6.2 project Edit: we also have a binding redirects in app.config

Edit #2: By taking the dll that lives deep in the nuget packages/ folder (4.6.24xxx in the properties details) and replacing it where our installer install the dlls (which was 4.6.26xxxx) magically makes everything work

Edit #3: Eventually just wiped out all of the changes, and manually installed/upgraded the RuntimeInfo nuget, installed the timezone nuget, and tested the install at each step. So unfortunately my only advice to others running into a simliar issue is to start over and do each step manually instead of letting nuget upgrade the dependencies for you.

mattjohnsonpint commented 5 years ago

@dot4qu - I've removed the dependency on System.Runtime.InteropServices.RuntimeInformation for all .NET Framework targets. This should fix the problem. Please try out release 3.0.0 and let me know if that resolves the issue. Thanks.

@clmcgrath - I also could not repro this on .NET Core 2.2. Please try again with release 3.0.0 and let me know if the problem persists. Thanks.

mattjohnsonpint commented 5 years ago

Closing this issue. If you are still having problems, please let me know and I'll re-open it. Thanks.