Title: Powershell 7.x : Cannot use type from dll (built for netstandard2.0) · Issue #12052 · PowerShell/PowerShell · GitHub
Open Graph Title: Powershell 7.x : Cannot use type from dll (built for netstandard2.0) · Issue #12052 · PowerShell/PowerShell
X Title: Powershell 7.x : Cannot use type from dll (built for netstandard2.0) · Issue #12052 · PowerShell/PowerShell
Description: Steps to reproduce Provided that there is a dotnet core sdk istalled, run script as below. What script does: Displays some debug stuff (dotnet core version, powershell version) Crates some directories e.g. where published library will be...
Open Graph Description: Steps to reproduce Provided that there is a dotnet core sdk istalled, run script as below. What script does: Displays some debug stuff (dotnet core version, powershell version) Crates some director...
X Description: Steps to reproduce Provided that there is a dotnet core sdk istalled, run script as below. What script does: Displays some debug stuff (dotnet core version, powershell version) Crates some director...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/12052
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Powershell 7.x : Cannot use type from dll (built for netstandard2.0)","articleBody":"\r\n\r\n\r\n\r\n# Steps to reproduce \r\n\r\nProvided that there is a dotnet core sdk istalled, run script as below.\r\nWhat script does:\r\n - Displays some debug stuff (dotnet core version, powershell version)\r\n - Crates some directories e.g. where published library will be copied\r\n - Creates ad hoc dot net core class lib project (targeted for `netstandard2.0`)\r\n - Compiles the project into dll\r\n - Loads the dll into powershell\r\n - Calls function `Hello` from the dll and expects to receive predefined output (== \"Works!\")\r\n\r\n\r\n```powershell\r\nFunction ShowErrorDetails\r\n{\r\n param(\r\n $ErrorRecord = $Error[0]\r\n )\r\n\r\n $out=\"\"\r\n $out+= $($ErrorRecord | Format-List -Property * -Force | out-string)\r\n $out+= $($ErrorRecord.InvocationInfo | Format-List -Property * | out-string)\r\n $Exception = $ErrorRecord.Exception\r\n for ($depth = 0; $Exception -ne $null; $depth++)\r\n {\r\n $out+= $(\"$depth\" * 80)\r\n $out+= $($Exception | Format-List -Property * -Force | out-string)\r\n $Exception = $Exception.InnerException\r\n }\r\n # emit return object\r\n $out\r\n}\r\n \r\n $myLibName=\"MyLib\"\r\n $myLibDllName=\"${myLibName}.dll\"\r\n $csProjName = \"${myLibName}.csproj\"\r\n $thisDir = Get-Location \r\n $workdir = Join-Path $thisDir \"workdir\"\r\n $libraryCodeDir = Join-Path $workdir $myLibName\r\n $csProjFilePath = Join-Path $libraryCodeDir $csProjName \r\n $publishedOutputDir = Join-Path $workdir \"published\"\r\n $dllFilePath = Join-Path $publishedOutputDir $myLibDllName\r\n \r\n Write-Host \"thisDir : '$thisDir'\"\r\n Write-Host \"myLibName : '$myLibName'\"\r\n Write-Host \"csProjName : '$csProjName'\"\r\n Write-Host \"workdir : '$workdir'\"\r\n Write-Host \"libraryCodeDir : '$libraryCodeDir'\"\r\n Write-Host \"csProjFilePath : '$csProjFilePath'\"\r\n Write-Host \"publishedOutputDir : '$publishedOutputDir'\"\r\n Write-Host \"myLibDllName : '$myLibDllName'\"\r\n Write-Host \"dllFilePath : '$dllFilePath'\"\r\n\r\n Write-host \"------ >>>>> Powershell version : \"\r\n $PsVersionTable | Out-Host\r\n \r\n Write-Host \"------ >>>>> Dotnet core version: \"\r\n dotnet --info\r\n \r\n Write-host \"------ >>>>> Creating $libraryCodeDir...\"\r\n New-item $libraryCodeDir -ItemType Directory -Force\r\n \r\n Write-Host \"`n------ >>>>> Creating library template in '$libraryCodeDir'\"\r\n dotnet new classlib --name $myLibName --output $libraryCodeDir --framework \"netstandard2.0\" --force\r\n \r\n\r\n$expectedOutput = \"Works!\"\r\n\r\n$codeContent = @\"\r\npublic static class MyClass\r\n{ \r\n public static string Hello()\r\n {\r\n return \"${expectedOutput}\";\r\n }\r\n}\r\n\"@\r\n\r\ntry \r\n{\r\n Set-Content -Path $libraryCodeDir/Class1.cs -Value $codeContent\r\n dotnet publish -c Debug -o ${publishedOutputDir} ${csProjFilePath}\r\n # if compilation was not successful\r\n if($global:LASTEXITCODE -ne 0 )\r\n {\r\n Write-Error \"------ >>>>> Compilation failed, cannot continue with the script..\"\r\n Exit 1\r\n }\r\n else\r\n {\r\n Write-Host \"------ >>>>> OK: compilation successful\"\r\n }\r\n\r\n Write-Host \"------ >>>>> Loading library...\"\r\n $bytes = [System.IO.File]::ReadAllBytes($dllFilePath)\r\n $loadedLib = [System.Reflection.Assembly]::Load($bytes)\r\n $loadedLib.GetTypes() | Out-Host\r\n $functionCallResult = [MyClass]::Hello()\r\n \r\n if($functionCallResult -eq $expectedOutput )\r\n {\r\n Write-Host \"------ >>>>> SUCCESS: Function call returned expected result\"\r\n }\r\n else\r\n {\r\n Write-Error \"------ >>>>> FAILURE: Function call unxpected result '${functionCallResult}' while expecting '${expectedOutput}'\"\r\n Exit 1\r\n }\r\n}\r\ncatch {\r\n ShowErrorDetails | Out-Host\r\n}\r\n\r\n```\r\n\r\n# Expected behavior\r\n After the script finishes , user should see line like\r\n```none\r\n------ >>>>> SUCCESS: Function call returned expected result\r\n```\r\n\r\n# Actual behavior\r\nI've added a debug function `ShowErrorDetails` to show full error details (code taken from book `Windows Powershell in action` 3rd edition) if something goes wrong.\r\nPowershell 7.0 cannot find the type from the library and at the end of error output it prints something like:\r\n\r\n```none\r\n00000000000000000000000000000000000000000000000000000000000000000000000000000000\r\nErrorRecord : Unable to find type [MyClass].\r\nWasThrownFromThrowStatement : False\r\nTargetSite : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext, System.Exception)\r\nStackTrace : at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)\r\n at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)\r\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\r\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\r\nMessage : Unable to find type [MyClass].\r\nData : {System.Management.Automation.Interpreter.InterpretedFrameInfo}\r\nInnerException :\r\nHelpLink :\r\nSource : System.Management.Automation\r\nHResult : -2146233087\r\n```\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\nThe issue is related only for powershell 7: \r\nI tested it on :\r\nWindows\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 7.0.0\r\nPSEdition Core\r\nGitCommitId 7.0.0\r\nOS Microsoft Windows 10.0.17763\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\nUbuntu:\r\n```none\r\n\r\nName Value\r\n---- -----\r\nPSVersion 7.0.0\r\nPSEdition Core\r\nGitCommitId 7.0.0\r\nOS Linux 5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020\r\nPlatform Unix\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n\r\nI have verified that this correctly WORKS platforms such as\r\nwindows powershell 5.1\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 5.1.17763.1007\r\nPSEdition Desktop\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nBuildVersion 10.0.17763.1007\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n```\r\n\r\nwindows powershell core 6.2.4\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 6.2.4\r\nPSEdition Core\r\nGitCommitId 6.2.4\r\nOS Microsoft Windows 10.0.17763\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\nubuntu powrshell core 6.2.4\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 6.2.4\r\nPSEdition Core\r\nGitCommitId 6.2.4\r\nOS Linux 5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020\r\nPlatform Unix\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n\r\n[ubuntu_pwsh6.2.4_output.txt](https://github.com/PowerShell/PowerShell/files/4298867/ubuntu_pwsh6.2.4_output.txt)\r\n[ubuntu_pwsh7_output.txt](https://github.com/PowerShell/PowerShell/files/4298868/ubuntu_pwsh7_output.txt)\r\n[windows_powershell_output.txt](https://github.com/PowerShell/PowerShell/files/4298869/windows_powershell_output.txt)\r\n[windows_pwsh6.2.4_output.txt](https://github.com/PowerShell/PowerShell/files/4298870/windows_pwsh6.2.4_output.txt)\r\n[windows_pwsh7_output.txt](https://github.com/PowerShell/PowerShell/files/4298871/windows_pwsh7_output.txt)\r\n\r\n\r\n","author":{"url":"https://github.com/grzegorz-wolszczak","@type":"Person","name":"grzegorz-wolszczak"},"datePublished":"2020-03-06T14:46:00Z","url":"https://github.com/PowerShell/PowerShell/issues/12052"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ea47a501-2e1c-168f-cd56-fd2b83633b34 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC08:5453:60483:8A462:6AFD48F9 |
| html-safe-nonce | 880800518e8ea7b3e56bc17644461826d1a3919a2cbb66f73a7c4ce457d23f9c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzA4OjU0NTM6NjA0ODM6OEE0NjI6NkFGRDQ4RjkiLCJ2aXNpdG9yX2lkIjoiNjY3Mjc3MTM1NDQ3Njc1OTI5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a620aab126a0be152da65837a47e947bcd44274a9d374cce0b5c766b08dd4ef6 |
| hovercard-subject-tag | issue:576977593 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/12052/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80a36a84a6e05bf8bfda1242d1228bfa7bcc959749d4f947a299a0d955534d13/PowerShell/PowerShell/issues/12052 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80a36a84a6e05bf8bfda1242d1228bfa7bcc959749d4f947a299a0d955534d13/PowerShell/PowerShell/issues/12052 |
| og:image:alt | Steps to reproduce Provided that there is a dotnet core sdk istalled, run script as below. What script does: Displays some debug stuff (dotnet core version, powershell version) Crates some director... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | grzegorz-wolszczak |
| hostname | github.com |
| expected-hostname | github.com |
| None | bdbacc25b921224ff0befcb9e629560a1255be51aec9991d6e3f95b5e9151474 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 556dd37bb0aceffb25724e151b5d858b3265b40b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width