System.Net.Http dll not loading issue in .Net Framework 4.8 project

Thejesh Pushpala 21 Reputation points
2024-06-04T10:36:45.6233333+00:00

Hi Team,

I have a

  1. ClassLibrary 1 project targeting .Net Framework 4.6 refering "System.Net.Http" of dll version 4.1.1.3
  2. ClassLibrary 2 project targeting .Net Framework 4.6 refering "System.Net.Http" of dll version 4.1.1.3
  3. WPF application targeting .Net Framework 4.8 by refering above 2 class libraries
  4. WIX v3 Installer project refering WPF application

In WPF application if i add System.Net.Http dll it is refering from "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\System.Net.Http.dll" not taking from "\packages\System.Net.Http.4.3.4\lib\net46" folder

So after msi installation below errors i'm getting

Could not load file or assembly 'System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Could not load file or assembly 'System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I have added below lines in app.config of WPF project, still not able to resolve this issue

<dependentAssembly>

			**<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>**

			**<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.1.1.3"/>**

		**</dependentAssembly>**
```Could you please help me out in resolving this issue

Thanks & Regards,

Thejesh.

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-06-05T09:35:16.4866667+00:00

    Hi,@Thejesh Pushpala. Welcome to Microsoft Q&A. 

    After my test, when installing System.Net.Http through the NuGet package, I found that the similar versions are only 4.1.1 and 4.1.3, and I did not find 4.1.1.3. Please confirm whether the System.Net.Http version is correct.

     

    The following is a case where I tested successfully. You can compare and modify it.

     

    1.Create several programs

     

    Class Library(.NET Framewrok4.6)

    a.Install System.Net.Http 4.1.3 via Nuget package

    b.Create a class and a method

    
    public class Class1
    
    {
    
        public async Task<String> Fun()
    
        {
    
            HttpClient client = new HttpClient();
    
    		
            {
    
                string responseBody = await response.Content.ReadAsStringAsync();
    
                return "Class1"+responseBody.Substring(0,10);
    
            }
    
               
    
        }
    
    }
    
    

     

    Class Library(.NET Framewrok4.6)

    a.Install System.Net.Http 4.1.3 via Nuget package

    b.Create a class and a method

    
    public class Class2
    
    {
    
        public async Task<String> Fun()
    
        {
    
            HttpClient client = new HttpClient();
    
            
            {
    
                string responseBody = await response.Content.ReadAsStringAsync();
    
                return "Class1"+responseBody.Substring(0,10);
    
            }
    
               
    
        }
    
    }
    
    

    WPF App(.NET Framework4.8)

    a.  Reference the above two Class programs(Add references directly through References)

    b.  Using Class1 and Class2

    
    public partial class MainWindow : Window
    
    {
    
        public MainWindow()
    
        {
    
            InitializeComponent();
    
            Task.Run(MyFun);
    
        }
    
     
    
        public async void MyFun()
    
        {
    
            Class1 class1 = new Class1();
    
            Class2 class2 = new Class2();
    
            var str1 = await class1.Fun();
    
            var str2 = await class2.Fun();
    
            MessageBox.Show(str1+" : "+str2);
    
        }
    
    }
    
    

    c.  Build the project

     

    2.Using WIX v3

     

    a.Install Wax, WiX v3 - Visual Studio 2022 Extension in Extensions->Manage Extensions

    b.Create a Setup Project for WiX v3

    c.Use References to reference only WPF projects

    d.Install wix 3.14.1 version via NuGet

    e.Open the WiX Setup Editor (Tools->WiX Setup Editor)

    f.Set the Root directory to INSTALLFOLDER

    g.Check the current project in Projects to install

    h.Select all in File mappings(Includes two Class Libraries referenced by the WPF project)

    i.Modify the Manufacturer and installation file names in Product.wxs

    Developer Name

    
    Manufacturer="AAA"
    
    

    Change the name of the installed folder to BBB

    
          <Fragment>
    
                <Directory Id="TARGETDIR" Name="SourceDir">
    
                      <Directory Id="ProgramFilesFolder">
    
                            <Directory Id="INSTALLFOLDER" Name="BBB" />
    
                      </Directory>
    
                </Directory>
    
          </Fragment>
    
    

    i.Build the program

    j.Install: Enter the current project folder, find the msi file in bin->Debug and double-click to run

    k.Run the program in C:\Program Files (x86)\BBB

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.