Custom cmdlet giving me a missing assembly error
Powershell gives me this error when I try run my cmdlet:
I'm using this guide to make API calls through this tutorial: https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c
which told me to add that assembly. When I compile it and use
ipmo
to add it to my powershell, I get that error when trying to run it. I was required to reference System.Net.Http.Formatting
to get ReadAsAsync<>()
to work (I think). Am I just building my project wrong?Stack Overflow
How do I make calls to a REST API using C#?
This is the code I have so far:
public class Class1
{
private const string URL = "https://sub.domain.com/objects.json?api_key=123";
private const string DATA = @&q...
36 Replies
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Okay thanks. I saw some other microsoft docs that looked similar enough to the stackoverflow post which is why I just settled for it. Ill go see what that top link is about
@oCeBeT I've used this doc to remake it. https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient
Still the same error:
Import-Module: Could not load file or assembly 'System.Management.Automation, Version=7.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Make HTTP requests with the HttpClient - .NET
Learn how to make HTTP requests and handle responses with the HttpClient in .NET.
This error is shown in powershell when I try to use
import-module
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Im using this to code my cmdlet https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/how-to-write-a-simple-cmdlet?view=powershell-7.4
System.Management.Automation is what it says to import to write a cmdlet. Im running powershell 7.4 for macos. As for template… I just used a class library and continued from there.
How to Write a Simple Cmdlet - PowerShell
How to Write a Simple Cmdlet
Idk why there are so many different documents to do one thing. Its like trying to find the infinity stones
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
TeBeCo
i honnestly never tried to create a custom PWSH Module, but what i can tell is that super old "windows powsrshell" is
powershell.exe
... BUT IS NOT "powershell / powershell core" which is pwsh
and pwsh is cross platform and runs on netcore 6+
I'm suspicious on the base template you're using
here's the one you're supposed to use:
https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/writing-portable-modules?view=powershell-7.4&viewFallbackFrom=powershell-7Embed Type
Link
Quoted by
<@689473681302224947> from #Custom cmdlet giving me a missing assembly error (click here)
React with ❌ to remove this embed.
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Oh 😭
Why is that the first thing that shows up on google
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
This might be why I'd switch to another engine
fuck SEO
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Actually fuck people who abuse it
Yea
best alternative IG
These are good results
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
for a search
For sure lol
I generated the template but I think it generated a template that uses an old version of C#:
csproj file:
Is there a way to migrate it to a newer version?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
TeBeCo
Quoted by
<@689473681302224947> from #Custom cmdlet giving me a missing assembly error (click here)
React with ❌ to remove this embed.
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
So I managed to port it using the dontet upgrade assistant tool
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
And I can successfully import the cmdlet
New
I just used the template as a starting point
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
hm
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
hmmm
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
dotnet new psmodule
generates an the old version I describedUnknown User•12mo ago
Message Not Public
Sign In & Join Server To View
so would there be a flag to use the latest version of .net?
Yes
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Hm
.net2 is really old :(
And I mean
I haven;t gotten any porting errors
I just get this one
Could not load file or assembly 'System.Net.Http, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified
System.Net.Http because I want my cmdlet to use an APIUnknown User•12mo ago
Message Not Public
Sign In & Join Server To View
On the csproj file I sent
Here
Ok thanks