question

Abhishek-9019 avatar image
1 Vote"
Abhishek-9019 asked DylanZhu-MSFT edited

Cannot load System.ServiceModel.Primitives.dll in UWP App

Hello

Have a UWP app which references a .Net standard 2.0 library.

This library uses System.ServiceModel.Primitives nuget package version 4.8.0

When running the app, it throws the exception "Cannot load System.ServiceModel.Primitives.dll version 4.8.0"

Have installed this same package in UWP app as well but the latest file does not get copied over to the output folder.

Tried to use app.config binding redirection but it does not seem to work.

Kindly advise

windows-uwpdotnet-standard
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Abhishek-9019 , I found a similar issue here: https://github.com/dotnet/wcf/issues/2546. Maybe you could try to install this nuget package: System.ServiceModel.Http(4.8.0), hope it could help you.

0 Votes 0 ·
DylanZhu-MSFT avatar image
0 Votes"
DylanZhu-MSFT answered DylanZhu-MSFT edited

Hi Abhishek,

I think it is the special feature of uwp project and the nuget package. Also, the nuget package is a system nuget package, it will not be output on the bin folder for new standard project. You should add these in csproj file so that it will appear.

Also, create a net standard lib project and a uwp project, install the same nuget package, use the same node, the uwp project still cannot output the dll. It is the special feature of the uwp project.

As a suggestion,
1) You can just copy the dll from C:\Users\'username'\.nuget\packages\system.servicemodel.primitives\4.8.0\lib into the bin folder of the uwp project.
2) you can add an automation msbuild script

Modify the csproj file of the uwp project

add <GeneratePathProperty>true</GeneratePathProperty> into your project and then add a msbuild target:

 <ItemGroup>
  <PackageReference Include="System.ServiceModel.Primitives"> 
       <Version>4.8.0</Version>
 <GeneratePathProperty>true</GeneratePathProperty>
     </PackageReference>
 </ItemGroup>
    
  <Target Name="CopyTheFile" AfterTargets="AfterCompile" Condition="!Exists('$(TargetDir)System.ServiceModel.Primitives.dll')"> 
 <ItemGroup>
 <File Include="$(PkgSystem_ServiceModel_Primitives)\lib\netstandard2.0\System.ServiceModel.Primitives.dll"></File>
 </ItemGroup>
 <Copy SourceFiles="@(File)" DestinationFolder="$(TargetDir)"></Copy>
 </Target>

Best Regards,
Dylan


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Abhishek-9019 avatar image
0 Votes"
Abhishek-9019 answered Abhishek-9019 commented

Thanks Dylan.

Implemented the automation build script as per above, and the file was successfully copied into the target folder.

However, still getting error as follows
System.IO.FileLoadException: 'Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.8.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

Tried to make an app.config file and implement bindingRedirect -- still same issue.

Pl advise

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You may be referenced System.ServiceModel.Primitives Version=4.8.0.0 but this is not registered to GAC. At present older version is available in GAC and runtime its not matching so only your getting this error.

0 Votes 0 ·
Abhishek-9019 avatar image Abhishek-9019 RajanikantHawaldar-9680 ·

So you mean all newer dlls have to be registered in GAC ?

Is there a way to tell the runtime to load a specific version from the application bin folder so that GAC registration is not required ...

0 Votes 0 ·

Hi @Abhishek-9019 , maybe you could try to add it as reference in your project.(Right-click reference->Click "Add Reference...")

0 Votes 0 ·
Show more comments

Use reflection to load particular version in specific path. Assembly.LoadFrom() method. how-the-runtime-locates-assemblies


0 Votes 0 ·
Show more comments