When UWP app project refers System.ServiceModel.Http NuGet package, it always crashes with following exception message and callstack.
((System.IO.FileLoadException)e.Exception).Message
~~~~~~~~
Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.5.0.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
~~~~~~~~e.Exception.RemoteStackTrace
~~~~~~~~
at App1.MainPage..ctor()
at App1.App..ctor()
at App1.UWP.MainPage..ctor()
at App1.UWP.App1_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage()
at App1.UWP.App1_UWP_XamlTypeInfo.XamlUserType.ActivateInstance()
~~~~~~~~
(Attached App1.zip sample project to reproduce the problem)
namespace App1{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var channel = new ChannelFactory
}
}
[ServiceContract()]
public interface ITest
{
}
}
~~~~~
Launch application without any problem.
Crash with 'System.IO.FileLoadException' at LoadApplication().
~~~~~
namespace App1.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
LoadApplication(new App1.App()); << Exception 'System.IO.FileLoadException' occurs at here
}
}
}
~~~~~
Affected Devices:
Windows Devices
Other version info
Xamarin Designer 4.12.1 (f3257e429)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin.Android SDK 8.3.3.2 (HEAD/dffc59120)
Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin.iOS and Xamarin.Mac SDK 11.12.0.4 (64fece5)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Same here
Workaround: You can avoid the problem by using version 4.4.4 package.
Looks like this is the same problem as #3031. We are investigating.
In .NET Core 2.1 release (released in this year), WCF Core assemblies have updated version numbers to 4.5... (minor version number changed). However Xamarin WCF facade, like System.ServiceModel.Primitives inbox version is Version=4.2.1.0. When Xamarin app reference to a .Netstandard library, which referece to 4.5.* WCF Core Nuget package, it fails to load WCF Core assembly, like System.ServiceModel.Primitives: Version=4.5.0.3. This is due to Xamarin façade System.ServiceModel.Primitives assembly version (4.2.1.0) is lower than the .NET standard library expected version (4.5.0.3). Xamarin WCF Core facades need to be updated to 4.5.. from below current versions released with VS.
System.ServiceModel.Primitives: Version=4.2.1.0
System.ServiceModel.Http: Version=4.1.3.0
System.ServiceModel.Duplex: Version=4.1.1.0
System.ServiceModel.NetTcp: Version=4.1.3.0
System.ServiceModel.Security: Version=4.0.4.0
System.ServiceModel.Web: Version=4.1.3.0
this looks like a potential duplicate of https://github.com/dotnet/wcf/issues/2438 too
We had further look at this issue. It doesn’t repro for Xamarin iOS app, but repro with Xamarin UWP app with Code sharing strategy of “.NET Standard”. Even after specifically adding reference to the same 4.5.3 WCF package in both UWP and Xamarin projects in the solution, the UWP process still loads the WCF assembly in the original UWP meta package (System.ServiceModel.Primitives: Version=4.2.1.0) first, which causes fileloadexception later when process tries to load newer version of System.ServiceModel.Primitives.dll. Looks like it is UWP project issue instead of Xamarin façade issue. per @marek-safar, mono whitelist these assemblies and they should work with any assembly version numbers with Xamarin products. UWP team is investigating the issue
The issue has been fixed in UWP version 6.2.3.
The problem is still (or again) here with latest packages and with .net standard 2.0 as shared library
Same issue with UWP version 6.2.10
.net Standard 2.0 PCL.
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'
Me too, same as pavloss.
What should I do, use 6.2.9, or 8, or ...?
I can try some things, but I am very weary of stumbling into one weird problem after the other, while trying to get an UWP variant working.
So far it has never succeeded. The Android one did work.
@a-einstein bit of a shot in the dark but this might be useful to you considering the error code and the fact that this is uwp:
https://devblogs.microsoft.com/oldnewthing/20200615-00/?p=103868