Skip to content

Add-Type failed to create a type that implements IWebProxy #2764

Description

This is a regression introduced by .NET Core 1.1 preview release libraries. It also happens on alpha.12 release.

Steps to reproduce

$RequiredAssembliesForInternalWebProxy = @( [System.Net.IWebProxy].Assembly.FullName, 
                                            [System.Uri].Assembly.FullName )

$SourceForInternalWebProxy = @" 
using System; 
using System.Net;

namespace Microsoft.PowerShell.Commands.PowerShellGet 
{ 
    /// <summary>
    /// Used by Ping-Endpoint function to supply webproxy to HttpClient
    /// We cannot use System.Net.WebProxy because this is not available on CoreClr
    /// </summary>
    public class InternalWebProxy : IWebProxy
    {
        Uri _proxyUri;
        ICredentials _credentials;

        public InternalWebProxy(Uri uri, ICredentials credentials)
        {
            Credentials = credentials;
            _proxyUri = uri;
        }

        /// <summary>
        /// Credentials used by WebProxy
        /// </summary>
        public ICredentials Credentials
        {
            get
            {
                return _credentials;
            }
            set
            {
                _credentials = value;
            }
        }

        public Uri GetProxy(Uri destination)
        {
            return _proxyUri;
        }

        public bool IsBypassed(Uri host)
        {
            return false;
        }
    }
} 
"@

Add-Type -ReferencedAssemblies $RequiredAssembliesForInternalWebProxy `
         -TypeDefinition $SourceForInternalWebProxy `
         -Language CSharp `
         -ErrorAction SilentlyContinue

Expected behavior

Succeeds

Actual behavior

Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more
information.
At line:1 char:1
+ Add-Type -ReferencedAssemblies $RequiredAssembliesForInternalWebProxy ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
    + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

PS D:\>
PS D:\> $Error[0].Exception.LoaderExceptions
Method 'GetProxy' in type 'Microsoft.PowerShell.Commands.PowerShellGet.InternalWebProxy' from assembly 'nxg304ea.wnz,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSVersion                      6.0.0-alpha
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
GitCommitId                    v6.0.0-alpha.12-104-g67e9bf6376b90c289d725c904280a2439de4dd3b
PSEdition                      Core
BuildVersion                   3.0.0.0
CLRVersion
SerializationVersion           1.1.0.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Blockedblocked on something external to this repoResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions