-1

I have worked with asp forms long time ago, now i must create a simple web interface, which uses powershell library.

[Nuget URI][1]https://www.nuget.org/packages/System.Management.Automation/

But seems impossible. using System.Management.Automation; <-- doesn't work any place.

Already tried installing the usual way (via cli and giu), copying the library to \bin folder and many other ways.

I often get the error:

Severity Code Description Project File Line Suppression State Error Could not load file or assembly 'System.Management.Automation, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

I am trying Web Forms because of simplicity, hope i am missing a simple thing.

Any help will be appreciated.

Garfius
  • 39
  • 8
  • "I am trying Web Forms because of simplicity" - you might wanna rethink that. Web Forms being simple couldn't be further from the truth. – mason May 04 '20 at 12:54
  • Well, as a backend developer, provides a simple way to create web user interfaces without knowing JavaScript or AJAX. Not bad at all. – Garfius May 04 '20 at 12:59
  • I spend most of my time in the backend too, yet I can still tell you that ASPX is not simple. Postbacks? Asynchronous postbacks? Managed client ID's? Postback triggers? ViewState? Lack of Dependency Injection? Difficulty testing? Yeah, Web Forms being simple is Microsoft looking back at it with rose-tinted glasses. It was great when it came out - C# as a web server language! But newer frameworks remove a lot of those leaky abstractions and are far simpler. MVC, Razor Pages, even Blazor will be simpler. Learning a bit of JS is going to be simpler than untangling ASPX mess. – mason May 04 '20 at 13:09
  • But i already know ASPX Forms, i just need to be able to include libs. – Garfius May 04 '20 at 13:15
  • If you don't want someone to pick at a silly statement like "I am trying Web Forms because of simplicity" then probably a good idea not to include it in your question in the first place. As for your issue referencing System.Management.Automation, remove all traces of it from your project (references, NuGet references, etc). Make sure you have no related binding redirects in your .config file. Do a Clean on your project. Once you've done that, try adding via NuGet again. – mason May 04 '20 at 13:24
  • Keep in mind that you've chosen Web Forms, which at best is based on .NET Framework 4.8 and can't reference System.Management.Automation v7 (latest stable on NuGet) because it's targeting .NET Core 3.1. You can probably obtain a suitable DLL from the Windows SDK, see [this question](https://stackoverflow.com/questions/1186270/referencing-system-management-automation-dll-in-visual-studio). – mason May 04 '20 at 13:32
  • Woah - settle down. I'm here trying to help you. If you don't want me to help, that's fine. I'm not sure what two languages you're referring to. You mean JavaScript and what else? I haven't suggested trying any silly stuff - they're just basic troubleshooting steps. They may not fix it, but you have to eliminate simple causes before looking for more complex solutions. I can assure you I've consumed many NuGet packages in my 10 years of developing software professionally, much of it spent in Web Forms. – mason May 04 '20 at 13:36
  • Ok, sorry 4 my manners, my apologies. Steps to reproduce: 1- create new forms project 2- Open nuget console 3-Run "Install-Package System.Management.Automation" 4-Namespace is not avialble, nor figures anywhere. 5- try copying to /bin folder, doesn't work either (couldn't load file or assembly) – Garfius May 04 '20 at 13:40
  • Right like I said, that's not going to work. If you don't specify a version, NuGet's going to install the latest version by default. And it looks like that version is for .NET Core 3.1 and newer. Did you look at the question I sent you where they suggested installing the Windows SDK and then referencing the assemblies that puts in place? – mason May 04 '20 at 13:42
  • It worked like charm on older aspx projects, also works now to create custom dll or windows forms apps. Just add dll library to project and you can use it. I have done exactly this to an aspx .net 4.51 project and worked. It seems i am missing some signature-validation-installing steps. – Garfius May 04 '20 at 13:51
  • When you say it worked before, do you mean installing other NuGet packages worked? Or specifically did you install System.Management.Automation before via this method? – mason May 04 '20 at 13:53
  • Both, i managed to use powershell objects within many projects of many kind, mostly downloading via nuget. – Garfius May 04 '20 at 14:03
  • Well give the suggestion from that other question a shot and see if that works for you now. – mason May 04 '20 at 14:03
  • Thanks, you where right. Just needed more detailed explanation. – Garfius May 04 '20 at 15:34

1 Answers1

-1

It was a version incompatibility, as mason pointed out on 1st post comments. Use the OS library located on C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.x.x.x.x__xxxxxxxxxxxxxx

.net Framework aspx is getting complex, don't be fooled on other kind of projects or scripts where you can use any binary you can find.

I used "\sn.exe -Vr yourDll.dll", and "sn.exe -Vl" to register and check the nuget library to GAC but, i got another error:

Could not load file or assembly 'System.Runtime.Extensions

Seems i must use the actual OS library, otherwise it won't work.

Also tried creating custom libraries and workes (myClass1 worked), no GAC registry needed. Also tried downloading mysql official library, which registers, and worked.

Anyways, hope helps to someone.

Garfius
  • 39
  • 8