Powershell: Add-Type loading wrong DLL file?

Created on 15 Oct 2019  路  6Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

Add-Type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword(24, 5)

Expected behavior

It should spit out a random 24 character password with at least 5 non-alpha characters. That bit of code above runs just like that on Windows PowerShell 5.1 but not on PS Core 7 - Preview 4

Actual behavior

Unable to find type [System.Web.Security.Membership].
At line:3 char:1
+ [System.Web.Security.Membership]::GeneratePassword(24, 5)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (System.Web.Security.Membership:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.4
PSEdition                      Core
GitCommitId                    7.0.0-preview.4
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Resolution-Answered

Most helpful comment

It is not PowerShell Core issue. The type and method are absent in .Net Core.

All 6 comments

Loading the types from that DLL seems to fail silently, as evidenced by the fact that adding -PassThru produces no output:

# Should emit the types loaded from the assembly - currently, there is no output.
Add-Type -AssemblyName System.Web -PassThru

It is not PowerShell Core issue. The type and method are absent in .Net Core.

Good point, @iSazonov.

According to https://docs.microsoft.com/en-us/dotnet/api/system.web?view=netcore-3.0, the assembly in .NET Core contains only 3 classes and 1 enum, and System.Web.Security.Membership is not among them.

However, there's something else going on here - please see #10802

The namespace supplies classes and interfaces that enable browser-server communication. This namespace includes the class, which provides extensive information about the current HTTP request; the class, which manages HTTP output to the client; and the class, which provides access to server-side utilities and processes. also includes classes for cookie manipulation, file transfer, exception information, and output cache control.
[System.Web.AspNetHostingPermission]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    AspNetHostingPermission                  System.Security.CodeAccessPermission

No problems :-)

[System.Web.<tab>]

Yes, but how does that relate to either this issue (we've established that System.Web.Security.Membership is not in .NET Core) or to #10802?

I think #10802

Was this page helpful?
0 / 5 - 0 ratings