Error in a textbox

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

Error in a textbox

Post by jramon.r@tv3.cat »

I have a very simple form with a label, a textbox and a button. When I run it and I try to introduce a text in the textbox it gets an error that it says:

>> Running (MapeigCorreccioExamenTS.psf) Script...
>> Platform: V4 64Bit (STA) (Elevated) (Forced)
ERROR: Method invocation failed because [System.Drawing.Font] does not contain a method named 'new'.
MapeigCorreccioExamenTS.Run.ps1 (136, 2): ERROR: At Line: 136 char: 2
ERROR: + $buttonAcceptar.Font = [System.Drawing.Font]::new('Arial Narrow', '8.25')
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : MethodNotFound
ERROR:
ERROR: Method invocation failed because [System.Drawing.Font] does not contain a method named 'new'.
MapeigCorreccioExamenTS.Run.ps1 (147, 2): ERROR: At Line: 147 char: 2
ERROR: + $textbox1.Font = [System.Drawing.Font]::new('Courier New', '8.25')
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : MethodNotFound
ERROR:
ERROR: Method invocation failed because [System.Drawing.Font] does not contain a method named 'new'.
MapeigCorreccioExamenTS.Run.ps1 (156, 2): ERROR: At Line: 156 char: 2
ERROR: + $labelEntraElDNIQueVolsCor.Font = [System.Drawing.Font]::new('Arial Narrow', '1 ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : MethodNotFound
ERROR:
>> Script Ended

The code is

$form1_Load={
#TODO: Initialize Form Controls here

}

$labelEntraElDNIQueVolsCor_Click={
#TODO: Place custom script here

}

$buttonAcceptar_Click={
#TODO: Place custom script here

$user = $textbox1.Text


$File = Import-Csv \\alpicat\public\cpa\ExamenTS\DNITSAleatori.csv -Delimiter ";"

$File | ForEach-Object {

if ($_.DNI -like $user)
{
$folder = $_.Aleatori
}
}

$pathfolder = "\\ssvspospocpa9\ExamenTS\Prova" + "\" + $folder

net use L: /delete /y
net use M: /delete /y

net use L: \\ssvspospocpa9\ExamenTS\Materials


net use M: $PathFolder

}



We have installed PowerShell Studio 2021 version 5.8.187.0 and is running on a Windows 2012 R2 64 bits

Can you help us? Thanks!!!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Error in a textbox

Post by jvierra »

What version of PowerShell are you running this under?
The best way to detect the error is to paste the following into a PS shell.


add-type -AssemblyName system.drawing
[System.Drawing.Font]::new('Arial Narrow', '8.25')
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

Re: Error in a textbox

Post by jramon.r@tv3.cat »

We have installed PowerShell Studio 2021 version 5.8.187.0 and is running on a Windows 2012 R2 64 bits

I've pasted what you said and the message error is the same

"Method invocation failed because [System.Drawing.Font] does not contain a method named "new"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Error in a textbox

Post by jvierra »

What version of PowerShell? Open PowerShell and get the version.
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

Re: Error in a textbox

Post by jramon.r@tv3.cat »

Powershell v.4.0
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

Re: Error in a textbox

Post by jramon.r@tv3.cat »

I think I need powershell version 5, can be it the solution? Thanks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Error in a textbox

Post by jvierra »

Yes. PS 5.1 will upgrade the net framework. YOU need to be sure 2012R2 is up to date or things will go wrong.

Note that 2012 is out of support so you may have many issues with updates and other problems. End of life was in 2018.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Error in a textbox

Post by jvierra »

Anayazius wrote: Thu Mar 25, 2021 2:10 am I am also interested in solving the problem. Thank you for your inquiry.
Please read the above answers and take corrective steps.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Error in a textbox

Post by jvierra »

Please follow these instructions and report the results.

[What version of PowerShell are you running this under?
The best way to detect the error is to paste the following into a PS shell (Not PowerShell Studio)

add-type -AssemblyName system.drawing
[System.Drawing.Font]::new('Arial Narrow', '8.25')
This topic is 2 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked