Binding redirects and .net core

Hi,
I have 3.1 .net core web application and Ive added Carter 5.1 as a reference. When I run the application I get
Unhandled exception. System.IO.FileLoadException: Could not load file or assembly ‘System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The located assembly’s manifest definition does not match the assembly reference. (0x80131040)
File name: ‘System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’
at Microsoft.Extensions.DependencyModel.DependencyContextJsonReader.Read(Stream stream)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.LoadContext(IDependencyContextReader reader, String location)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.Load(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContext.Load(Assembly assembly)
at Carter.DependencyContextAssemblyCatalog…ctor(Assembly entryAssembly) in /home/runner/work/Carter/Carter/src/Carter/DependencyContextAssemblyCatalog.cs:line 37
at Carter.DependencyContextAssemblyCatalog…ctor() in /home/runner/work/Carter/Carter/src/Carter/DependencyContextAssemblyCatalog.cs:line 29
at Carter.CarterExtensions.AddCarter(IServiceCollection services, Action1 options, DependencyContextAssemblyCatalog assemblyCatalog, Action1 configurator) in /home/runner/work/Carter/Carter/src/Carter/CarterExtensions.cs:line 147
at APIWebApplication.Startup.ConfigureServices(IServiceCollection services) in /Users/JohnMoshakis/Documents/develop/Echoes/Core/APIWebApplication/Startup.pas:line 33

I’ve had this problem before in .net framework apps and fixed it by using binding redirects. Seems to come up where different nuget references reference different versions of something.

In this case it seems like a problem because I’ve only got a Carter reference and the sdk.

This is the example

APIWebApplication.zip (654.8 KB)

The only difference Ive seen so far is that ebuild generates deps.json with System.Text.Json 4.7.1, whereas using dotnet does 4.7.0
Screen Shot 2020-03-01 at 5.41.06 PM

Im wondering if this issue is because of the way that references are resolved. ebuild always picks the highest version on my machine, rather than the lowest to satisfy constraints. ie Carter has
Microsoft.Extensions.DependencyModel (>= 3.1.0)
but because 3.1.2 is available its picked it up which results in a later version of System.Text.Json

Cheers,
John

Isn’t that the proper behavior if you specify a version and no upper bound (I.e. not „|“)?

In theory yes but i always seem to hit this where the file version is different to the nuget version.

Do you know why the exception appears ?

The ms tooling seems to pick the lowest like in this case.

What am I missing here, as far as I can tell, Microsoft.Extensions.DependencyModel 3.1.2 explicitly asks for 4.7.1, sop getting 4.7.0 would be wrong.

  <group targetFramework=".NETStandard2.0">
    <dependency id="System.Text.Json" version="4.7.1" exclude="Build,Analyzers" />
  </group>

What I did now (to try out) make any indirect dependencies use a closing “]” to limit the version. so now it resolved like this:

D:                      Package Microsoft.NETCore.App.Ref found in repository <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Available Versions of 'Microsoft.NETCore.App.Ref': 3.1.0, 3.0.1, 3.0.0, 3.0.0-rc1-19456-20, 3.0.0-preview9-19423-09, 3.0.0-preview8-28405-07, 3.0.0-preview7-27912-14, 3.0.0-preview6-27804-01, 3.0.0-preview5-27626-15, 3.0.0-preview4-27615-11, 3.0.0-preview3-27503-5.
D:                      Package Microsoft.NETCore.App.Ref:3.0.1 found in repository <NuGetRepository https://api.nuget.org/v3/index.json>.

D:                      Checking <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Checking <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Package Microsoft.ASPNETCore.App.Ref found in repository <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Available Versions of 'Microsoft.ASPNETCore.App.Ref': 3.1.2, 3.1.0, 3.0.1, 3.0.0, 3.0.0-preview5-19227-01, 3.0.0-preview4-19216-03, 3.0.0-preview3-19153-02.
D:                      Package Microsoft.ASPNETCore.App.Ref:3.0.1 found in repository <NuGetRepository https://api.nuget.org/v3/index.json>.

D:                      Checking <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Package Carter found in repository <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Available Versions of 'Carter': 3.11.0.
D:                      Package Carter version [5.1.0] could not be matched in repository <NuGetRepository file:///Users/mh/.nuget/packages/>.

D:                      Checking <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Package Carter found in repository <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Available Versions of 'Carter': 5.1.0, 5.0.0, 4.2.0, 4.1.0, 4.0.0, 3.11.0, 3.10.0, 3.9.0, 3.8.0, 3.7.0, 3.6.0, 3.5.0, 0.0.0-alpha.
D:                      Package Carter:5.1.0 found in repository <NuGetRepository https://api.nuget.org/v3/index.json>.
                        Adding dependency FluentValidation:8.5.1] from Carter:5.1.0.

D:                      Checking <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Package FluentValidation found in repository <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Available Versions of 'FluentValidation': 8.1.2.
D:                      Package FluentValidation version 8.5.1] could not be matched in repository <NuGetRepository file:///Users/mh/.nuget/packages/>.

D:                      Checking <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Package FluentValidation found in repository <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Available Versions of 'FluentValidation': 9.0.0-preview3, 9.0.0-preview2, 9.0.0-preview1, 8.6.2, 8.6.1, 8.6.0, 8.5.1, 8.5.0, 8.5.0-preview5, 8.5.0-preview4, 8.5.0-preview3, 8.5.0-preview2, 8.5.0-preview1, 8.4.0, 8.3.0, 8.2.3, 8.2.2, 8.2.1, 8.2.0, 8.1.3, 8.1.2, 8.1.1, 8.1.0, 8.1.0-preview2, 8.1.0-preview1, 8.0.101, 8.0.100, 8.0.0, 8.0.0-rc1, 8.0.0-preview4, 8.0.0-preview3, 8.0.0-preview2, 8.0.0-preview1, 7.6.105, 7.6.104, 7.6.103, 7.6.102, 7.6.101, 7.6.100, 7.6.0, 7.6.0-preview1, 7.5.2, 7.5.1, 7.5.0, 7.4.0, 7.3.4, 7.3.3, 7.3.2, 7.3.1, 7.3.0, 7.3.0-beta3, 7.3.0-beta2, 7.3.0-beta1, 7.2.1, 7.2.0, 7.2.0-beta3, 7.2.0-beta2, 7.2.0-beta1, 7.1.1, 7.1.0, 7.1.0-beta1, 7.0.3, 7.0.2, 7.0.1, 7.0.0, 7.0.0-beta3, 7.0.0-beta2, 7.0.0-beta1, 6.4.1, 6.4.1-beta1, 6.4.0, 6.4.0-rc4, 6.4.0-rc3, 6.4.0-rc2, 6.4.0-rc1, 6.4.0-beta9, 6.4.0-beta8, 6.4.0-beta7, 6.4.0-beta6, 6.4.0-beta5, 6.4.0-beta4, 6.4.0-beta3, 6.4.0-beta2, 6.4.0-beta10, 6.4.0-beta1, 6.3.4-alpha, 6.3.3-alpha, 6.2.1, 6.2.1-beta1, 6.2.0, 6.2.0-beta1, 6.1.0, 6.0.2, 6.0.1, 6.0.0, 5.6.2, 5.6.1, 5.6.0, 5.5.0, 5.4.0, 5.3.0, 5.2.0, 5.1.0, 5.0.0.1, 5.0.0, 4.0.0.1, 4.0.0, 3.4.6, 3.4.0, 3.3.1, 3.3.0, 3.2.0, 3.1.0, 3.0.0.1, 3.0.0, 2.0.0, 1.3.0.
D:                      Package FluentValidation:8.5.1 found in repository <NuGetRepository https://api.nuget.org/v3/index.json>.
                        Adding dependency System.ComponentModel.Annotations:4.4.1] from FluentValidation:8.5.1.

D:                      Checking <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Package System.ComponentModel.Annotations found in repository <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Available Versions of 'System.ComponentModel.Annotations': 4.4.1.
D:                      Package System.ComponentModel.Annotations:4.4.1 found in repository <NuGetRepository file:///Users/mh/.nuget/packages/>.
                        Adding dependency Microsoft.Extensions.DependencyModel:3.1.0] from Carter:5.1.0.

D:                      Checking <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Checking <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Package Microsoft.Extensions.DependencyModel found in repository <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Available Versions of 'Microsoft.Extensions.DependencyModel': 3.1.2, 3.1.1, 3.1.0, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-preview6-27804-01, 3.0.0-preview5-27626-15, 3.0.0-preview4-27615-11, 3.0.0-preview3-27503-5, 3.0.0-preview-27324-5, 2.1.0, 2.1.0-rc1, 2.1.0-preview2-26406-04, 2.1.0-preview1-26216-03, 2.0.4, 2.0.3, 2.0.0, 2.0.0-preview2-25407-01, 2.0.0-preview1-002111, 1.1.9, 1.1.2, 1.1.1, 1.1.0, 1.1.0-preview1-001100, 1.0.500-preview2-1-003177, 1.0.3, 1.0.1-beta-000933, 1.0.0, 1.0.0-rc2-final, 1.0.0-rc2-002702, 0.0.1-alpha.
D:                      Package Microsoft.Extensions.DependencyModel:3.1.0 found in repository <NuGetRepository https://api.nuget.org/v3/index.json>.
                        Adding dependency System.Text.Json:4.7.0] from Microsoft.Extensions.DependencyModel:3.1.0.

D:                      Checking <NuGetRepository file:///Users/mh/.nuget/packages/>
D:                      Checking <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Package System.Text.Json found in repository <NuGetRepository https://api.nuget.org/v3/index.json>
D:                      Available Versions of 'System.Text.Json': 4.7.1, 4.7.0, 4.6.0, 2.0.0.11, 2.0.0.10, 2.0.0.9, 2.0.0.8, 2.0.0.7, 2.0.0.6, 2.0.0.5, 2.0.0.4, 2.0.0.3, 2.0.0.2, 2.0.0.1, 2.0.0, 1.9.9.9, 1.9.9.8, 1.9.9.7, 1.9.9.6, 1.9.9.5, 1.9.9.4, 1.9.9.3, 1.9.9.2, 1.9.9.1, 1.9.9, 1.9.8, 1.9.7, 1.9.6, 1.9.5, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9.0, 1.8.0, 1.7.0, 1.6.0, 1.5.0, 1.4.0, 1.3.0, 1.2.0, 1.1.0, 1.0.0.
D:                      Package System.Text.Json:4.7.0 found in repository <NuGetRepository https://api.nuget.org/v3/index.json>.
                        Adding dependency Microsoft.OpenApi:1.1.4] from Carter:5.1.0.

I have no idea if this is the proper fix or will break other stuff, but I’ll out it in a build so you can test it.

If it’s not, I propose introducing a new internal delimiter, say “}”, which I would encode to be softer than “]” and mean "don’t use a higher version unless necessary.

1 Like

Started a new build for you, 20200302-121057-elements-develop [setups]

I tested, adding, say, an explicit System.Text.Json:4.7.1 to the project, it will upgrade to that and still compile. so I think this fix should be safe.

It looks good. The simple example works and it hasnt seem to have impacted a bigger console that runs on mono.

Ive been trying to create a .net core version of the bigger console app but that doesn’t seem to be working. It starts but seems to just hang, Im trying to work out what the issue is.

1 Like

I’m having a problem working out what the issue is.

I do a dotnet SailingLogSelfHosted.Core.dll from the commandline and I see a logging message but then nothing else

Under the debugger in Fire it just hangs and is never able to resolve breakpoints

Do you think its reasonable for me to expect the debugger to work ?

Whats interesting is that on Window is if I attach visual studio all I see is a flood of messages

Exception thrown: ‘System.ArgumentException’ in Moshine.MessagePipeline.Transports.MicrosoftAzureServiceBus.dll
Exception thrown: ‘System.ArgumentException’ in Moshine.MessagePipeline.Transports.MicrosoftAzureServiceBus.dll
Exception thrown: ‘System.ArgumentException’ in Moshine.MessagePipeline.Transports.MicrosoftAzureServiceBus.dll
Exception thrown: ‘System.ArgumentException’ in Moshine.MessagePipeline.Transports.MicrosoftAzureServiceBus.dll

Moshine.MessagePipeline.Transports.MicrosoftAzureServiceBus is a remote project reference of a .net standard library.

The code which I think is causing a problem is

  Console.WriteLine('StartAsync');

  try

    using scope := _serviceProvider.CreateScope do
    begin
      var bus := scope.ServiceProvider.GetRequiredService<IBus>;
      await bus.InitializeAsync;
    end;
  except
    on E:Exception do
    begin
      Console.WriteLine($'{E.Message}');
    end;
  end;
  Console.WriteLine('StartedAsync');

bus.InitializeAsync would be in Moshine.MessagePipeline.Transports.MicrosoftAzureServiceBus

StartAsync is the last thing I see.

What’s the message?

Does the app not run at all, or do only the breakpoints not work? Any app, or just this one? whats the exact symptoms, at what stage does it hang? Launching, Starting, Started?

Surely yes.

Ok. That’d of course be an issue of the app actually throwing these, I assume, and the debugger is thus working ok in Water? Does it stop on the exception? if not, is that exception type maybe set to be ignored? If it doers stop, whats the callstack?

(Oddly, “Exception thrown” is not something Water would print on its own; out seems that these messages just come thru stdout?). Can I see a screenshot of this?

Hard to say from just that :(. I take it you don’t see the Console.WriteLine($‘{E.Message}’);?

FWIW, here:

a simple .NET Core app debugs fine, including Breakpoints

From the console all I see is

$ dotnet SailingLogSelfHosted.Core.dll
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using ‘C:\Users\john\AppData\Local\ASP.NET\DataProtection-Keys’ as key repository and Windows DPAPI to encrypt keys at rest.
StartAsync

StartAsync is my debugging message.

The app seems to run and hang after that message.

Both Fire and Water behave the same way and hang with breakpoints unresolved. The ArgumentException message is from the output window of visual studio when I attach it to the dotnet exe

The console app is a .net core api web application.

I thought it might be a reference issue but I removed all the references I had added and it didnt hang until I added them back and then added the code in the ConfigureServices services method in Startup.pas

As I mentioned a asp.net core api with Carter works fine, its just this console app.

You know .net core web applications log this before starting

info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\develop\WebApplication16\bin\Debug

I dont see this when I add

await bus.InitializeAsync;

to the code

then we gotta figure out what makes this project different from others. DO you see any errors in Console.app or the Activity window?

I dont see anything in console or activity. The code I add that causes the problem is using Azure servicebus, I also have console apps using just that and that works ok.

If I do a control c on the console app, I get this displayed

info: Microsoft.Hosting.Lifetime[0]
Application is shutting down…

and it never shutsdown

The pieces seem to work correctly separately. That is a carter web application and azure servicebus code but inside this console app something together is causing them to hang.

Ok, but so clearly the app is running, and whatever the problem is is in the code that runs, then?

I know what I did wrong. The code is expecting a config file with values, there isnt one so Im passing null strings some servicebus functions.

I didnt expect nothing displayed on the console.

1 Like