funny versions of System.IO.Pipelines and System.Runtime.CompilerServices.Unsafe are being loaded at runtime #258

Closed
opened 2025-12-29 08:24:51 +01:00 by adam · 15 comments
Owner

Originally created by @eli-darkly on GitHub (Mar 11, 2020).

This may not really be a WireMock.Net issue, but I'm hoping that maybe someone can shed some light on what's going on.

I'm trying to use WireMock.Net inside some .NET test code that's being run with the Xamarin runtime in iOS. The target framework is netstandard2.0. I have no problem building or deploying the app. But at runtime, I get this error from the FluentMockServer constructor:

---- System.AggregateException (Could not load file or assembly 'System.IO.Pipelines, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.)
-------- System.IO.FileNotFoundException assembly 'System.IO.Pipelines, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

There are two odd things about this. First, I can't find where the dependency on System.IO.Pipelines is coming from; it doesn't seem to be a transitive dependency of my project or of WireMock.Net. That makes me think that some kind of dynamic loading is going on, possibly due to Owin/Kestrel-related stuff that I don't understand.

Second, there isn't any 4.0.0 version of System.IO.Pipelines— at least, not in NuGet, where the earliest available version is 4.5.0. So if this were a dependency that the compiler knew about, it would fail at compile time.

On a hunch, I tried adding an explicit dependency on System.IO.Pipelines (v4.7.0) in my own code. This actually did get rid of the error I mentioned. But now it's complaining instead (again at runtime only) about not being able to find a different assembly: System.Runtime.CompilerServices.Unsafe, v4.0.4. Again, that's a version that does not exist in NuGet. Unfortunately, adding my own dependency on a later version of this package doesn't fix the error, so I assume whoever is trying to use it has specified a stricter version constraint than they did for the other package.

I presume the ultimate reason this is happening has something to do with details of what is or isn't included in the Xamarin runtime— I see that a similar issue (https://github.com/WireMock-Net/WireMock.Net/issues/281) was reported earlier in Xamarin Android (although I'm deploying the same test code in Android and not having the error there). @StefH I know testing in Xamarin is probably impractical for you, but since you clearly know more about the ASP.NET Core web tools than I do, I'm just wondering if you know anything about where these dependencies are coming from.

Originally created by @eli-darkly on GitHub (Mar 11, 2020). This may not really be a WireMock.Net issue, but I'm hoping that maybe someone can shed some light on what's going on. I'm trying to use WireMock.Net inside some .NET test code that's being run with the Xamarin runtime in iOS. The target framework is `netstandard2.0`. I have no problem building or deploying the app. But at runtime, I get this error from the FluentMockServer constructor: ``` ---- System.AggregateException (Could not load file or assembly 'System.IO.Pipelines, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.) -------- System.IO.FileNotFoundException assembly 'System.IO.Pipelines, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. ``` There are two odd things about this. First, I can't find where the dependency on `System.IO.Pipelines` is coming from; it doesn't seem to be a transitive dependency of my project or of WireMock.Net. That makes me think that some kind of dynamic loading is going on, possibly due to Owin/Kestrel-related stuff that I don't understand. Second, there isn't any 4.0.0 version of `System.IO.Pipelines`— at least, not in NuGet, where the earliest available version is 4.5.0. So if this were a dependency that the compiler knew about, it would fail at compile time. On a hunch, I tried adding an explicit dependency on `System.IO.Pipelines` (v4.7.0) in my own code. This actually did get rid of the error I mentioned. But now it's complaining instead (again at runtime only) about not being able to find a different assembly: `System.Runtime.CompilerServices.Unsafe`, v4.0.4. Again, that's a version that does not exist in NuGet. Unfortunately, adding my own dependency on a later version of this package doesn't fix the error, so I assume whoever is trying to use it has specified a stricter version constraint than they did for the other package. I presume the ultimate reason this is happening has something to do with details of what is or isn't included in the Xamarin runtime— I see that a similar issue (https://github.com/WireMock-Net/WireMock.Net/issues/281) was reported earlier in Xamarin Android (although I'm deploying the same test code in Android and _not_ having the error there). @StefH I know testing in Xamarin is probably impractical for you, but since you clearly know more about the ASP.NET Core web tools than I do, I'm just wondering if you know anything about where these dependencies are coming from.
adam added the question label 2025-12-29 08:24:51 +01:00
adam closed this issue 2025-12-29 08:24:51 +01:00
Author
Owner

@LevYas commented on GitHub (May 18, 2020):

@eli-darkly

  1. You can use dependency walkers such as IlSpy or many others to see all the dependencies
  2. This version notation means relation to major versions. You can see this kind of references everywhere, i.e. see the screenshot in this answer https://stackoverflow.com/a/36404201/3087417

Also, there is information about other dependency walkers in other answers.
About your error, it looks like something is not installed, or maybe a binding redirects issue.

@LevYas commented on GitHub (May 18, 2020): @eli-darkly 1. You can use dependency walkers such as IlSpy or many others to see all the dependencies 2. This version notation means relation to major versions. You can see this kind of references everywhere, i.e. see the screenshot in this answer https://stackoverflow.com/a/36404201/3087417 Also, there is information about other dependency walkers in other answers. About your error, it looks like something is not installed, or maybe a binding redirects issue.
Author
Owner

@eli-darkly commented on GitHub (May 18, 2020):

@LevYas:

You can use dependency walkers such as IlSpy or many others to see all the dependencies

That would be true if this were a build-time dependency that is defined in the usual way. But as I said, this appears to be coming from something that's dynamically loaded, possibly by using System.Reflection.Assembly. The implementation types that make up Kestrel do not appear if you walk the dependency tree of WireMock.Net; the transitive dependencies stop at Owin and Microsoft.Owin, leading me to believe that those packages use dynamic loading to obtain the underlying implementation.

This version notation means relation to major versions

Yes, I know about major version references in dependencies. I have not seen such a version in a "Could not load file or assembly" error, though; don't those normally refer to the actual, specific version that it was trying to load? As I mentioned, when it complained about not being able to find System.Runtime.CompilerServices.Unsafe, the error referenced 4.0.4 rather than 4.0.0.

@eli-darkly commented on GitHub (May 18, 2020): @LevYas: > You can use dependency walkers such as IlSpy or many others to see all the dependencies That would be true if this were a build-time dependency that is defined in the usual way. But as I said, this appears to be coming from something that's dynamically loaded, possibly by using `System.Reflection.Assembly`. The implementation types that make up Kestrel do not appear if you walk the dependency tree of WireMock.Net; the transitive dependencies stop at `Owin` and `Microsoft.Owin`, leading me to believe that those packages use dynamic loading to obtain the underlying implementation. > This version notation means relation to major versions Yes, I know about major version references in dependencies. I have not seen such a version in a "Could not load file or assembly" error, though; don't those normally refer to the actual, specific version that it was trying to load? As I mentioned, when it complained about not being able to find `System.Runtime.CompilerServices.Unsafe`, the error referenced `4.0.4` rather than `4.0.0`.
Author
Owner

@LevYas commented on GitHub (May 18, 2020):

@eli-darkly

don't those normally refer to the actual, specific version that it was trying to load?

Usually, I see only .0.0-versions. 4.0.4 is strange, I think it means specific version when it matters.

if I were you I would try to diagnose the problem further using tools for runtime assembly bindings checks like mentioned here: https://stackoverflow.com/a/54011223/3087417 It could provide some useful insights.

@LevYas commented on GitHub (May 18, 2020): @eli-darkly > don't those normally refer to the actual, specific version that it was trying to load? Usually, I see only .0.0-versions. `4.0.4` is strange, I think it means specific version when it matters. if I were you I would try to diagnose the problem further using tools for runtime assembly bindings checks like mentioned here: https://stackoverflow.com/a/54011223/3087417 It could provide some useful insights.
Author
Owner

@eli-darkly commented on GitHub (May 18, 2020):

@LevYas As I mentioned in the original description, my code is running in an iOS environment via Xamarin. It's not possible to use a tool like fuslogvw.exe there.

@eli-darkly commented on GitHub (May 18, 2020): @LevYas As I mentioned in the original description, my code is running in an iOS environment via Xamarin. It's not possible to use a tool like fuslogvw.exe there.
Author
Owner

@LevYas commented on GitHub (May 19, 2020):

@eli-darkly but there should be some iOS-specific tools, I think. Maybe some extended verbose logging or so on. Because this doesn't look like a general problem, so more information is needed.

@LevYas commented on GitHub (May 19, 2020): @eli-darkly but there should be some iOS-specific tools, I think. Maybe some extended verbose logging or so on. Because this doesn't look like a general problem, so more information is needed.
Author
Owner

@LevYas commented on GitHub (May 19, 2020):

Do you use Mono? If so, maybe this could be helpful https://www.mono-project.com/docs/advanced/runtime/logging-runtime-events/

As for versions, I found out that the NuGet version is not the same as the assembly version, and there is a recommendation here to not change the assembly versions every time to avoid version hell. The example with different versions of the library "Immutable":

What is interesting, assemblies inside the folders for different netstandard have the same version.

@LevYas commented on GitHub (May 19, 2020): Do you use Mono? If so, maybe this could be helpful https://www.mono-project.com/docs/advanced/runtime/logging-runtime-events/ As for versions, I found out that the NuGet version is not the same as the assembly version, and there is a recommendation [here ](https://docs.microsoft.com/en-us/archive/blogs/suzcook/when-to-change-fileassembly-versions) to not change the assembly versions every time to avoid version hell. The example with different versions of the library "Immutable": ![](https://habrastorage.org/webt/qy/wg/5m/qywg5mjhpkuogm6yez7uhnxitji.jpeg) What is interesting, assemblies inside the folders for different netstandard have the same version.
Author
Owner

@eli-darkly commented on GitHub (May 19, 2020):

@LevYas

Because this doesn't look like a general problem, so more information is needed.

Of course it's not a general problem. I made prominent disclaimers in my original post saying that I knew this was weird and probably only tangentially related to WireMock, but that I was posting it in the long-shot hope that Stef, due to having worked with the ASP.NET Core web frameworks, might know something relevant about their dependencies. That's all. Please don't feel compelled to try to diagnose this issue for me if you don't happen to know any weird quirks of ASP.NET Core; answers like "have you tried to enable verbose logging" are not what I was looking for.

@eli-darkly commented on GitHub (May 19, 2020): @LevYas > Because this doesn't look like a general problem, so more information is needed. Of course it's not a general problem. I made prominent disclaimers in my original post saying that I knew this was weird and probably only tangentially related to WireMock, but that I was posting it in the long-shot hope that Stef, due to having worked with the ASP.NET Core web frameworks, might know something relevant about their dependencies. That's all. Please don't feel compelled to try to diagnose this issue for me if you don't happen to know any weird quirks of ASP.NET Core; answers like "have you tried to enable verbose logging" are not what I was looking for.
Author
Owner

@LevYas commented on GitHub (May 19, 2020):

Ok, sorry for bothering :)

@LevYas commented on GitHub (May 19, 2020): Ok, sorry for bothering :)
Author
Owner

@StefH commented on GitHub (Sep 6, 2020):

@eli-darkly
I think I cannot really help you on this question.

Does maybe upgrading your unit-test project to .NET Core 3.x help?

@StefH commented on GitHub (Sep 6, 2020): @eli-darkly I think I cannot really help you on this question. Does maybe upgrading your unit-test project to .NET Core 3.x help?
Author
Owner

@eli-darkly commented on GitHub (Apr 3, 2021):

@StefH Just FYI, I never did manage to figure this out. Changing the project to .NET Core is not an option, because these are tests that run in Xamarin; the target framework has to be either MonoAndroid or XamarinIOs. So it is using the .NET Standard target of WireMock.Net. Unfortunately, while https://github.com/WireMock-Net/WireMock.Net/issues/534 looks like an extremely similar assembly loading problem, the workaround described there is not an option because Xamarin doesn't support binding redirects in app.config.

So what I ended up doing in Xamarin was to switch to EmbedIO. I'm still using WireMock.NET in test code that has to run in .NET Framework 4.5.x, because .NET Framework 4.5.x isn't compatible with .NET Standard and EmbedIO only has a .NET Standard target.

@eli-darkly commented on GitHub (Apr 3, 2021): @StefH Just FYI, I never did manage to figure this out. Changing the project to .NET Core is not an option, because these are tests that run _in Xamarin_; the target framework has to be either MonoAndroid or XamarinIOs. So it is using the .NET Standard target of WireMock.Net. Unfortunately, while https://github.com/WireMock-Net/WireMock.Net/issues/534 looks like an extremely similar assembly loading problem, the workaround described there is not an option because Xamarin doesn't support binding redirects in app.config. So what I ended up doing in Xamarin was to switch to EmbedIO. I'm still using WireMock.NET in test code that has to run in .NET Framework 4.5.x, because .NET Framework 4.5.x isn't compatible with .NET Standard and EmbedIO only has a .NET Standard target.
Author
Owner

@StefH commented on GitHub (Apr 3, 2021):

Hello @eli-darkly,

Sorry that you could not get it working with WireMock.Net

Can you maybe provide a sample project which shows the error ? Then maybe I can debug it on my system ?

@StefH commented on GitHub (Apr 3, 2021): Hello @eli-darkly, Sorry that you could not get it working with WireMock.Net Can you maybe provide a sample project which shows the error ? Then maybe I can debug it on my system ?
Author
Owner

@eli-darkly commented on GitHub (Apr 6, 2021):

@StefH I'll try to put together a minimal example if I have time, but it wouldn't be practical for me to send you the actual project I'm working on.

@eli-darkly commented on GitHub (Apr 6, 2021): @StefH I'll try to put together a minimal example if I have time, but it wouldn't be practical for me to send you the actual project I'm working on.
Author
Owner

@StefH commented on GitHub (Jan 6, 2022):

Hello @eli-darkly,

Is this issue still relevant, or can it be closed?

@StefH commented on GitHub (Jan 6, 2022): Hello @eli-darkly, Is this issue still relevant, or can it be closed?
Author
Owner

@StefH commented on GitHub (May 3, 2022):

Hello @eli-darkly,

Is this issue still relevant, or can it be closed?

@StefH commented on GitHub (May 3, 2022): Hello @eli-darkly, Is this issue still relevant, or can it be closed?
Author
Owner

@StefH commented on GitHub (Aug 16, 2022):

Closing,,,

@StefH commented on GitHub (Aug 16, 2022): Closing,,,
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#258