nager / Nager.Date

Worldwide holidays (REST API), NuGet or docker container :earth_americas:
https://date.nager.at
MIT License
1.06k stars 171 forks source link

.net 4.7.2 - Using HolidaySystem creates error #626

Closed mytechmicke closed 3 months ago

mytechmicke commented 3 months ago

NuGet Package Version

2.2.2

More information

Hi, Stack trace in my project:

at Nager.LicenseSystem.LicenseKeyValidator.Validate(String licenseKey, LicenseInfo& licenseInfo) at Nager.Date.Helpers.LicenseHelper.CheckLicenseKey(String licenseKey) at Nager.Date.HolidaySystem.CheckLicense(String licenseKey) at Nager.Date.HolidaySystem.TryGetHolidayProvider(CountryCode countryCode, IHolidayProvider& holidayProvider) at Nager.Date.HolidaySystem.IsHoliday(DateTime date, CountryCode countryCode, HolidayTypes holidayTypes, Holiday[]& publicHolidays) at BookingSentinel.CalendarHelper.IsDayHoliday(DateTime day) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\CalendarHelper.cs:line 85 at BookingSentinel.CalendarHelper.IsDayWorkDay(DateTime day) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\CalendarHelper.cs:line 64 at BookingSentinel.CalendarHelper.AdjustStopDateForHolidaysAndWeekends(DateTime start, DateTime stop) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\CalendarHelper.cs:line 538 at BookingSentinel.BookingSentinel.OnSaving(IBooking item) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\BookingSentinel.cs:line 158

and also:

{"Could not load file or assembly 'System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"}

This occurs when using HolidaySystem. I have set license key both in function and in creation of class. What is wrong here? Best regards, Mikael

tinohager commented 3 months ago

Hello Mikael

Can you give me more information about the .net version used in your application?

mytechmicke commented 3 months ago

Hi, 4.7.2

tinohager commented 3 months ago

I have test it with a fresh 4.7.2 project without issues.

Can you try this to your app.config

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.5.5" newVersion="4.5.5" />
      </dependentAssembly>
    </assemblyBinding>

https://github.com/confluentinc/confluent-kafka-dotnet/issues/1507#issuecomment-961521387

mytechmicke commented 3 months ago

Hi, Now the file looks like this:

<?xml version="1.0" encoding="utf-8"?>

Is this correct? This did not work, same error. Best regards, Mikael

From: Tino Hager @.> Sent: Tuesday, 26 March 2024 20:49 To: nager/Nager.Date @.> Cc: Mikael Lindner @.>; Author @.> Subject: Re: [nager/Nager.Date] Using HolidaySystem creates error -> Could not load file or assembly System.Memory, Version=4.0.1.2 (Issue #626)

I have test it with a fresh 4.7.2 project without issues.

Can you try this to your app.config

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

  <dependentAssembly>

    <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>

    <bindingRedirect oldVersion="0.0.0.0-4.5.5" newVersion="4.5.5" />

  </dependentAssembly>

</assemblyBinding>

confluentinc/confluent-kafka-dotnet#1507 (comment)https://github.com/confluentinc/confluent-kafka-dotnet/issues/1507#issuecomment-961521387

— Reply to this email directly, view it on GitHubhttps://github.com/nager/Nager.Date/issues/626#issuecomment-2021334707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHWDOKLMEI4YRGCRT7RS6JLY2G7JFAVCNFSM6AAAAABFJRWL7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRRGMZTINZQG4. You are receiving this because you authored the thread.Message ID: @.**@.>>

tinohager commented 3 months ago

Can you validate this in your project file? (.csproj)

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    ....
  </PropertyGroup>
mytechmicke commented 3 months ago

Hi, Same error. I will try on another machine/project.

mytechmicke commented 3 months ago

Hi, Exactly same error on a different machine and another project.

tinohager commented 3 months ago

Do you have the same error with a clean new .net 4.7.2 project?

mytechmicke commented 3 months ago

Hi, I made a new WinForm project and there it works. My other projects are of type Class Library. It does not work in any of them. Can you see any differences between project types that might affect the functions and create this error?

tinohager commented 3 months ago

I could imagine that there is another dependency in the other project that includes an old version of System.Text.Json and that causes a conflict.

mytechmicke commented 3 months ago

Hi, The only json part in my projects is: Newtonsoft.json >= 12.0.1 Can this be a problem?

mytechmicke commented 3 months ago

Hi, I have done a chart over which dll's are used, enclosed pdf file. The one called Mobigo is the software that I'm extending and the columns shows which dll's are used and what version. In Nager column I have the versions from install, see enclosed image. Do you see any problems with the different versions? Nager-Mobigo-files-versions.pdf NagerInstall

mytechmicke commented 3 months ago

Hi, I tried to overwrite all common DLL's (used all from Nager) and got a different error:

at System.ReadOnlySpan`1..ctor(T[] array) at Nager.LicenseSystem.LicenseKeyValidator.Validate(String licenseKey, LicenseInfo& licenseInfo) at Nager.Date.Helpers.LicenseHelper.CheckLicenseKey(String licenseKey) at Nager.Date.HolidaySystem.CheckLicense(String licenseKey) at Nager.Date.HolidaySystem.TryGetHolidayProvider(CountryCode countryCode, IHolidayProvider& holidayProvider) at Nager.Date.HolidaySystem.IsHoliday(DateTime date, CountryCode countryCode, HolidayTypes holidayTypes, Holiday[]& publicHolidays) at BookingSentinel.CalendarHelper.IsDayHoliday(DateTime day) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\CalendarHelper.cs:line 87 at BookingSentinel.CalendarHelper.IsDayWorkDay(DateTime day) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\CalendarHelper.cs:line 64 at BookingSentinel.CalendarHelper.AdjustStopDateForHolidaysAndWeekends(DateTime start, DateTime stop) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\CalendarHelper.cs:line 542 at BookingSentinel.BookingSentinel.OnSaving(IBooking item) in C:\Users\Micke\Documents\Visual Studio 2022\Projects\BookingFactory\BookingFactory\BookingSentinel\BookingSentinel.cs:line 158

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

tinohager commented 3 months ago

Hi, The only json part in my projects is: Newtonsoft.json >= 12.0.1 Can this be a problem?

it may also be another package which in turn has a dependency on system.text.json.

tinohager commented 3 months ago

Hi, I made a new WinForm project and there it works. My other projects are of type Class Library. It does not work in any of them. Can you see any differences between project types that might affect the functions and create this error?

This Setup work on my test, Class1.cs contains the Nager.Date logic image

tinohager commented 3 months ago

Hi, I have done a chart over which dll's are used, enclosed pdf file. The one called Mobigo is the software that I'm extending and the columns shows which dll's are used and what version. In Nager column I have the versions from install, see enclosed image. Do you see any problems with the different versions? Nager-Mobigo-files-versions.pdf NagerInstall

The versions in the pdf make no sense, these versions do not exist according to nuget.org image

mytechmicke commented 3 months ago

Hi, I just took file version in properties of each dll. Perhaps that was wrong, I don't know how else get the version.

tinohager commented 3 months ago

how can i reach you best do you want to send me an e-mail?

mytechmicke commented 3 months ago

Hi, mikael@mytech.se

tinohager commented 3 months ago

Hi, can you try with the new version of Nager.LicenseSystem 1.1.0

mytechmicke commented 3 months ago

Hi, just sent you an email.

tinohager commented 3 months ago

The new package now has legacy json support without dependencies. Please also use the updated license key in the sponsor dashboard.