0

We have a .NET Framework 4.7.1 project

I installed IdentityModel 6.0.0 with the NuGet Package Manager. It installed the following dependencies for me:

Microsoft.Bcl.AsyncInterfaces 6.0.0
System.Buffers 4.5.1
System.Memory 4.5.4
System.Numerics.Vectors 4.5.0
System.Text.Json 6.0.3
System.ValueTuple 4.5.0

I'm trying to run the following code to see if a service exists:

var disco = await clientAuth.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest
{
    Address = server,
    Policy =
    {
        ValidateIssuerName = false
    }
});
if (disco.IsError) {...}

But, it keeps generating an error. I managed to drill down into the code, and finally came upon this: var result = System.Text.Json.JsonDocument.Parse("{"issuer":"https:....}").RootElement;

The error I get on this is:

Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

at System.Text.Json.JsonReaderHelper.IndexOfOrLessThan(Byte& searchSpace, Byte value0, Byte value1, Byte lessThan, Int32 length) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs:line 208

at System.Text.Json.Utf8JsonReader.ConsumeString() in /_/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs:line 1276

at System.Text.Json.Utf8JsonReader.ConsumePropertyName() in /_/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs:line 1227

at System.Text.Json.Utf8JsonReader.ReadSingleSegment() in /_/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs:line 852

at System.Text.Json.Utf8JsonReader.Read() in /_/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs:line 272

at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs:line 1092

at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs:line 697

at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 json, JsonDocumentOptions options) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs:line 271

at System.Text.Json.JsonDocument.Parse(String json, JsonDocumentOptions options) in /_/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs:line 316

at Citadel.Framework.APICalls.APIBase.<Setup>d__3.MoveNext() in C:\Dev\Src\Tyrus\Production\Tyrus_5_1\Citadel.Framework.APICalls\APIBase.cs:line 86

I managed to drill down to the ConsumeString method, but couldn't learn anything.

The most annoying of all is I can't load version 4.1.4 for System.Numerics.Vectors

In the Nuget Manager, only the following versions are available:

4.5.0 - current
4.4.0
4.3.0
4.1.1
4.1.0
4.0.0

I'm getting preciously little on the internet regarding this specific issue, and I've tried everything I could find without any luck. I've tried clearing my nuget cache. I can't remember how many times I've removed and readded the dependencies, I've cleaned my solution and rebuild it. I tried a number of combinations of:

<dependentAssembly>
    <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.1.4.0" />
</dependentAssembly>
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
hannodb
  • 223
  • 1
  • 11
  • ``. You *don't have* version 4.1.4.0. – Robert Harvey May 04 '22 at 13:16
  • You could also try *removing* the bindingRedirect. – Robert Harvey May 04 '22 at 13:17
  • @RobertHarvey I did try it without bindingRedirect. I added it in an attempt to get it to work. I realise I don't have version 4.1.4.0, the question is, how do I get it if that version is not available in the drop down? – hannodb May 04 '22 at 13:30
  • 1
    4.5.0 is the *semantic version number*. It doesn't have anything to do with the assembly version number anymore. The kind of idiocy that somehow is inevitable with any version numbering scheme. To get the 4.1.4.0 assembly, you do in fact need the 4.5.0 nuget package. Do note the error message, it is not a "found the assembly but it is the wrong version", it is a "could not find it at all" error. The question provides no clue, do check the build directory for the presence of the file. – Hans Passant May 04 '22 at 13:44
  • @HansPassant Thanks for that valuable information. Had I known that, I could've saved a lot of time. Followup question: You're right: System.Numerics.Vectors is not in the bin folder, but why would that be? I would assume that if its added as a reference, is should have been compiled to the bin folder? Am I missing a setting or something? – hannodb May 04 '22 at 13:51
  • Hard to imagine you'd want to burn yet more time, based on nothing but a blind guess. Gather facts, look at the detailed build trace to see why the file isn't getting copied. – Hans Passant May 04 '22 at 14:00
  • 1
    Hmm. I get this in the output: Consider app.config remapping of assembly "System.Numerics.Vectors, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.1.3.0" [] to Version "4.1.4.0" [] to solve conflict and get rid of warning. I'll try using – hannodb May 04 '22 at 14:14

1 Answers1

0

Turns out that adding the following line in your root project file will magically make all the problems go away:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

Odd that I didn't find any article suggesting this.

hannodb
  • 223
  • 1
  • 11