C
C#6mo ago
Exilon

Custom cmdlet giving me a missing assembly error

Powershell gives me this error when I try run my cmdlet:
Get-UserFromId: Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Get-UserFromId: Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
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
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
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
Exilon
Exilon6mo ago
@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.
Exilon
Exilon6mo ago
This error is shown in powershell when I try to use import-module
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
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
Exilon
Exilon6mo ago
Idk why there are so many different documents to do one thing. Its like trying to find the infinity stones
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX6mo ago
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-7
Embed Type
Link
From TeBeCo
React with ❌ to remove this embed.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
Oh 😭 Why is that the first thing that shows up on google
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
This might be why I'd switch to another engine fuck SEO
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
Actually fuck people who abuse it Yea best alternative IG These are good results
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
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:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Project</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-06">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Project</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-06">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
Is there a way to migrate it to a newer version?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX6mo ago
TeBeCo
From TeBeCo
React with ❌ to remove this embed.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
So I managed to port it using the dontet upgrade assistant tool
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
And I can successfully import the cmdlet New I just used the template as a starting point
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
hm
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
hmmm
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
dotnet new psmodule generates an the old version I described
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
so would there be a flag to use the latest version of .net? Yes
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
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 API
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Exilon
Exilon6mo ago
On the csproj file I sent Here Ok thanks
Want results from more Discord servers?
Add your server
More Posts