Program Tip

System.Net.Http 4.2.0.0의 이상한 문제를 찾을 수 없습니다.

programtip 2020. 10. 23. 08:21
반응형

System.Net.Http 4.2.0.0의 이상한 문제를 찾을 수 없습니다.


나는 나를 미치게 만드는 이상한 문제가있다…

Cosmos DB와 관련된 기능을위한 래퍼 클래스가있는 간단한 클래스 라이브러리 프로젝트 (전체 .NET Framework, 4.6.1)가 있습니다. 따라서이 프로젝트에 "Microsoft.Azure.DocumentDB"NuGet 패키지 1.19.1을 추가했습니다. 그 외에 "Newtonsoft.Json"NuGet 패키지 10.0.3과 몇 가지 "Microsoft.Diagnostics.EventFlow. *"NuGet 패키지에 대한 참조가 있습니다.

지금까지 모든 것이 오류없이 컴파일됩니다.

그러나 간단한 Service Fabric Stateless Service (Full .NET Framework 4.6.1)에서 사용되는 래퍼 클래스에 도달하자마자 다음 코드 줄을 실행 해보십시오.

_docClient = new DocumentClient(new Uri(cosmosDbEndpointUrl), cosmosDbAuthKey);

런타임에이 이상한 오류가 발생합니다.

System.IO.FileNotFoundException 발생 HResult = 0x80070002
메시지 = 파일 또는 어셈블리 'System.Net.Http, Version = 4.2.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'또는 해당 종속성 중 하나를로드 할 수 없습니다. 시스템이 지정된 파일을 찾을 수 없습니다.
Source = StackTrace : at Microsoft.Azure.Documents.Client.DocumentClient.Initialize (Uri 1 desiredConsistencyLevel) at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, NullableserviceEndpoint , ConnectionPolicy connectionPolicy, Nullable 1 desiredConsistencyLevel)

내부 예외 1 : FileNotFoundException : 파일 또는 어셈블리 'System.Net.Http, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'또는 해당 종속성 중 하나를로드 할 수 없습니다. 시스템이 지정된 파일을 찾을 수 없습니다.

System.Net.Http 어셈블리가 전혀 발견되지 않는 이유에 대한 단서가 전혀 없습니다. 클래스 라이브러리 프로젝트에 .Net Framework 어셈블리“System.Net.Http 4.0.0.0”에 대한 어셈블리 참조도 있습니다.

내가 이해하지 못하는 것은 4.2.0.0으로의 이상한 바인딩 리디렉션이 있다는 것입니다 – 그 바인딩은 어디에서 왔습니까? 이 문제를 해결하기 위해 클래스 라이브러리를 사용하는 Service Fabric Service의 app.config에 다음 리디렉션을 추가하려고했습니다.

그러나 여전히 차이는 없지만 런타임에 여전히 오류가 발생합니다.

단서가있는 사람 있나요? 그런 문제를 본 사람이 있습니까?

감사합니다. OliverB


직면 한 문제는 Visual Studio, 특히 System.Net.Http v4.2.0.0. 그러나 NuGet을 통해 참조를 수행해야하는 새로운 방식을 채택하면 최신 버전 System.Net.Http4.3.3에는 dll 버전 4.1.1.2가 포함됩니다.

문제는 빌드 시간과 런타임에 VS가 참조를 무시하고 알고있는 DLL을 참조하려고 시도한다는 것입니다.

해결 방법 :

  • System.Net.Http에 대한 모든 참조가 NuGet을 통해 수행되는지 확인하십시오.
  • 빌드 시간 오류 : VS 2017 ( c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\) 과 함께 제공되는 System.Net.Http.dll의 확장을 변경 (또는 다른 곳으로 이동 ... 기본적으로 제거 ) 다른 버전을 가지고 있다면 경로가 약간 다를 것입니다.
  • 런타임 오류 : 어셈블리 바인딩 리디렉션 추가

Google에서 온라인으로 살펴보면 이에 대해 Microsoft와 관련된 몇 가지 미해결 문제를 발견 할 수 있으므로 앞으로이 문제를 해결할 것입니다.

도움이 되었기를 바랍니다.

최신 정보:

빌드 에이전트에서 작동하기 위해이 문제에 대한 몇 가지 영구적 인 수정 사항을 찾을 때 새 NuGet PackageReference 모델 (에서 .csproj아님 packages.config)으로 마이그레이션하면 더 잘 작동하는 경향이 있음을 확인했습니다. 이 업그레이드를 수행하는 방법에 대한 가이드 링크는 다음과 같습니다. https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference


바인딩 리디렉션을 제거하면 효과가 있었으므로 제거해 볼 수 있습니다.

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

@AndreiU가 이미 준 답변과 로컬에서 런타임 오류를 재현하는 방법에 대한 추가 사항입니다.

로컬이 아닌 Azure에 배포 할 때 아래와 같은 런타임 오류가 발생했습니다.

파일 또는 어셈블리 'System.Net.Http, Version = 4.2.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'또는 해당 종속성 중 하나를로드 할 수 없습니다. 시스템이 Company.Project에서 Company.Project.Service.CompanyIntegrationApiService..ctor (Uri baseAddress) \ r \ n에서 지정된 파일을 찾을 수 없습니다. ","ExceptionType ":"System.IO.FileNotFoundException ","StackTrace ":" .BackOffice.Web.Controllers.OrderController..ctor () in C : \ projects \ company-project \ src \ Company.Project.BackOffice.Web \ Controllers \ Order \ OrderController.cs : line 30 \ r \ n at lambda_method ( Closure) \ r \ n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create (HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) "}} 또는 그 종속성 중 하나. 시스템이 Company.Project에서 Company.Project.Service.CompanyIntegrationApiService..ctor (Uri baseAddress) \ r \ n에서 지정된 파일을 찾을 수 없습니다. ","ExceptionType ":"System.IO.FileNotFoundException ","StackTrace ":" .BackOffice.Web.Controllers.OrderController..ctor () in C : \ projects \ company-project \ src \ Company.Project.BackOffice.Web \ Controllers \ Order \ OrderController.cs : line 30 \ r \ n at lambda_method ( Closure) \ r \ n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create (HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) "}} 또는 그 종속성 중 하나. 시스템이 Company.Project에서 Company.Project.Service.CompanyIntegrationApiService..ctor (Uri baseAddress) \ r \ n에서 지정된 파일을 찾을 수 없습니다. ","ExceptionType ":"System.IO.FileNotFoundException ","StackTrace ":" .BackOffice.Web.Controllers.OrderController..ctor () in C : \ projects \ company-project \ src \ Company.Project.BackOffice.Web \ Controllers \ Order \ OrderController.cs : line 30 \ r \ n at lambda_method ( Closure) \ r \ n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create (HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) "}}

어셈블리를 살펴보기 시작했을 때 웹 프로젝트와 서비스 프로젝트가 System.Net.Http.

웹 프로젝트 :

여기에 이미지 설명 입력

봉사 프로젝트 :

여기에 이미지 설명 입력

이것은 버전의 불일치로 인해 발생한다고 생각하기 쉽지만 여기서 핵심은 오류를 확인하는 것 The system cannot find the file specified.입니다.

path 속성을 살펴보면 웹 프로젝트가 .Net Framework 어셈블리를 대상으로하는 반면 서비스는 Visual Studio 2017의 어셈블리를 대상으로한다는 것을 알 수 있습니다. 서버에 Visual Studio 2017이 설치되어 있지 않으므로 런타임 오류가 발생합니다.

웹 경로 :

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll

서비스 경로 :

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll

설정으로 간단하게 뭔가 Copy Local하는 true모든 경우에 그러나하지, 문제를 해결할 수 있습니다.

여기에 이미지 설명 입력

로컬 컴퓨터에서 오류를 재현 System.Net.Http.dll하려면 Visual Studio 특정 폴더에서 필요한 항목 제거하기 만하면 됩니다. 이렇게하면 런타임 오류가 발생하고 빌드 오류가 발생할 수 있습니다. 이것들이 수정되면 모든 것이 작동해야하지만 적어도 나를 위해했습니다.

당신이 설치 한 경우 System.Net.Http를 통해 NuGet확인 어셈블리보고 사용되는 .csproj버전. System.Net.Http 4.3.4예를 들어 다음 어셈블리를 제공합니다.

<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
  <Private>True</Private>
  <Private>True</Private>
</Reference>

Jenkins, TeamCity 또는 AppVeyor와 같은 빌드 서버를 사용하는 경우 누락 된 런타임도 .dll거기에 존재할 수 있습니다. 이 경우 System.Net.Http의 NuGet 버전을 사용하거나 누락 된 항목을 .dll로컬에서 삭제하는 것이 도움이되지 않을 수 있습니다. 이 오류를 해결하려면 찾을 수없는 버전과 특정 PublicKeyToken. 그 후 바인딩 리디렉션을 생성하거나 Web.config또는 App.config프로젝트에 따라 달라집니다. 제 경우에는 4.0.0.0을 대신 사용하고 싶습니다.

<dependentAssembly>
  <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

문제에 대한 좋은 Github 스레드 :

https://github.com/dotnet/corefx/issues/22781


웹 서비스를 서버 중 하나에 배포 할 때이 오류가 발생했습니다. 이 프로젝트는 서버에 설치되지 않은 .Net 프레임 워크 4.7.2를 대상으로했습니다. 서버에 4.7.2 프레임 워크를 설치하면 문제가 해결되었습니다.


문제를 해결하기 위해 내가 한 일은 web.config에서 모든 바인딩을 제거하고

Update-Package -reinstall

이것은 아마도 거기에있을 필요가 없을 것 같은 오래된 바인딩을 제거하고 실제로 좋은 청소를했습니다.


웹 프로젝트의 대상 프레임 워크를 4.6으로 다운 그레이드하는 간단한 솔루션 하나를 찾았습니다.

나는 클라이언트와 웹 응용 프로그램, .net 프레임 워크 4.7.1을 가진 클라이언트와 동일한 웹을 가지고 있으며 웹용 대상 .net 프레임 워크를 다운 그레이드 할 때 동일한 문제에 직면 해 있습니다.


System.Net.HttpNuGet을 사용하여 설치했습니다 . 여기에서 가져올 수 있습니다.

https://www.nuget.org/packages/System.Net.Http/

ASP.NET MVC내가 목표로하고 있는 프로젝트 .NET 4.6.1. IIS ExpressVisual Studio 2019로 디버깅하는 동안 내 컴퓨터에서 완벽하게 작동합니다 .

Azure에 배포 된 애플리케이션을 실행하려고 할 때 문제가 발생했습니다. 이 오류가 발생했습니다.

파일 또는 어셈블리 'System.Net.Http, Version = 4.2.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'또는 해당 종속성 중 하나를로드 할 수 없습니다.

제 경우에 실제로 효과가 있었던 것은 .csproj 파일을 열고 System.Net.Http다음 스크린 샷에서와 같이 검색하는 것입니다.

여기에 이미지 설명 입력

.csproj파일에 다음 버전이 있는지 확인하십시오 4.1.1.3.

<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

<HintPath>받는 실제로 점 ..\packages이다 Nuget에서 폴더,이 Nuget에 의해 설치된 실제 버전입니다. 이 특정 버전이 배포되면 서버 측에서도 복원되며 모든 것이 바인드 리디렉션과 함께 작동해야합니다.

... 따라서 바인딩 리디렉션 은 다음과 같이이 특정 버전을 언급해야 Web.config합니다.

<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>

This fixed the problem in my case after a couple of commits to Azure Kudu. The Azure web site finally started with no errors.


I had the same problem. In the end I solved it by changing the Deploy-FabricApplication.ps1 to something like this

$binFolder = "$LocalFolder\..\..\..\..\Bin"

$httpDllLocation = "$binFolder\System.Net.Http.dll"
$codeFolder = "$ApplicationPackagePath\[ProjectName].ServicesPkg\Code"
$configFile = "$codeFolder\[ProjectName].Services.exe.config"

Copy-Item $httpDllLocation -Destination $codeFolder 

$appConfig = [xml](cat $configFile)
$appConfig.configuration.runtime.assemblyBinding.dependentAssembly | foreach {

    $name = $_.assemblyIdentity.name
    #Write $name
    if($name -eq 'System.Net.Http')
    {
        Write 'System.Net.Http changed'

        $_.bindingRedirect.newVersion = '4.2.0.0'
    }
}
$appConfig.Save($configFile)

I found an 4.2.0.0 System.Net.Http.dll that is x64. Before deploying this script copies the dll to the package directory and changes the config file to explicitly use this file. I also wrote a blog about my System.Net.Http problems at http://gertjanvanmontfoort.blogspot.nl/2017/11/systemnethttp-dll-version-problems.html

Do not forget to replace the [ProjectName] with your own project name

Hope this helps, feel free to ask


For me was something really strange. Needed hours of debugging after found what was the issue. It did not happen locally but only when using jenkins to build the project.

I had a small library using dotnet standart 2.0 and the main project was WCF project which is based on normal .NET(mine was specifically v4.6.1). But in the startup class of the dotnet standart library I had some code that looked like this:

public static class CoreModule
{
    public static IServiceCollection AddStaticDataConfiguration(
        this IServiceCollection services, Func<IServiceProvider, IStaticDataConfiguration>  staticDataConfiguration) 
    {  
        services.TryAddSingleton(staticDataConfiguration);
        services.TryAddSingleton<Func<HttpClient>>(x =>
        {
            var configuration = staticDataConfiguration(x);

            return configuration.ClientResolver ?? (() => new HttpClient());
        });
        return services;
    }
}

IStaticDataConfiguration interface looks like below:

public interface IStaticDataConfiguration
{
    //..... some stuff

    Func<HttpClient> ClientResolver { get; set; }
}  

This interface resides inside of the dotnet standart library while the implementation is outside of it(its located in WCF project).

From outside of the library I was calling the AddStaticDataConfiguration method like below:

serviceCollection.AddStaticDataConfiguration(p =>
{
    var staticDataConfig = p.GetService<IStaticDataConfiguration>();
    return new StaticDataProviderConfiguration
    {
        //...some other stuff
        ClientResolver = () => restRequestFactory.GetInstrumentedClient("StaticDataService") //this returns an HttpClient
    };
});

The problem is that I am passing a Func<HttpClient> from a normal .NET project to a dotnet standart library which for some crazy reason dotnet standart does not like and maybe it thinks HttpClient is coming from different classes, as a result throwing System.Net.Http 4.x.x.x not found exception. When removed the code to not accept a HttpClient from a normal .NET project but creating a new func inside the library itself its happy and working fine. Hope this might help somebody else since this error is happening for so many reasons :)


My solution was similar to @Raquib's. My project was 4.7.2 and worked just fine on my PC. Whenever I deployed to our dev server I would get the issue mentioned in the question. Turns out the highest .net version on the server was 4.6.1. Downgrading my project to 4.6.1 fixed the problem. Upgrading the server's .net version was not an option for me.


First delete from your local filesystem:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\Syste.Net.Http.dll

Then remove all references in Projects and, add 4.0 reference.
This solved my problem to me.


After struggling with this for a couple of days I finally got the .Net 4.7.2/System.Net.Http problem fixed for my project. In addition to changing the *.csproj file to target the framework version 4.7.2 I had to also update app.config in the projects from

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

to:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />

참고 URL : https://stackoverflow.com/questions/47570912/strange-issue-with-system-net-http-4-2-0-0-not-found

반응형