dotnet / WatsonWebserver

Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
MIT License
403 stars 83 forks source link

WatsonWebserver.Core.dll - System.Text.Json loading issue. #150

Closed GitHubProUser67 closed 2 months ago

GitHubProUser67 commented 2 months ago

Hello, with the last version of the nuget package, an issue started to happen, which is related to assembly loading.

image

This states that the assembly System.Text.Json is unable to be loaded.

I tried to copy it to the output directory, didn't help.

For some reasons this happens when loading it as a library alone, loading it within a server using the package makes this issue disapear.

So to sum it up:

HTTPServer -> Plugin -> WatsonWebserver.Core.dll -> Fails.

WatsonWebserver.Core.dll -> Costura.Fody -> HTTPSecureServer -> Plugin -> Success.

jchristn commented 2 months ago

Strange, this isn't happening for me using WatsonWebserverTest. Any additional steps to help reproduce?

GitHubProUser67 commented 2 months ago

Yep, strange issue, the steps to reproduce are this:

Go to this project https://github.com/GitHubProUser67/MultiServer3

Dowload it via the download zip function, then press build.bat

After this go to ~BuildOutput/Multiserver/Debug|Release and start the HTTPServer.exe

jchristn commented 2 months ago

Just built it and didn't receive an error.

image

GitHubProUser67 commented 2 months ago

Yep, that's because there is no plugins.

Ideally compile a plugin such as HomeWebTools and start the server.

jchristn commented 2 months ago

Sorry, I built from VS instead of running build.bat. Reporting back in a moment.

jchristn commented 2 months ago

Yep, I see the exception.

It looks like you're running into an issue caused by dependency loading from using things like Assembly.LoadFromFile and other similar methods.

I've had to deal with this in other projects, and to get around it, I've had to ensure that subordinate projects correctly packed dependencies in their output. Specifically, this in the .csproj file. e.g. if project A is dynamically loading project B, project B must have this in the .csproj file, specifically within the top-level property group, to ensure the right DLLs are packed:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>

I'm happy to chat with you to go through a very, very similar example to yours that caused me to go through this exact exercise and deal with this same problem. Please feel free to email me at joel dot christner at gmail dot com.

However, since this isn't an issue with the library, I'll close this and move it to discussions.

Cheers, Joel