Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom image: Exception calling ".ctor" with "1" argument(s): "Parameter is not valid." #105

Closed
tripplehelix opened this issue Sep 1, 2021 · 14 comments

Comments

@tripplehelix
Copy link

When I try to use a custom png I get this error, are there requirements or something I'm missing?

New-Object: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:390
Line |
 390 |  … $OldImage = New-Object -TypeName System.Drawing.Bitmap -ArgumentList  …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling ".ctor" with "1" argument(s): "Parameter is not valid."

RuntimeException: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:391
Line |
 391 |          $ROWS = $OldImage.Height / $OldImage.Width * $COLUMNS
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Attempted to divide by zero.

New-Object: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:394
Line |
 394 |  …   $Bitmap = New-Object -TypeName System.Drawing.Bitmap -ArgumentList  …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling ".ctor" with "2" argument(s): "Parameter is not valid."

MethodInvocationException: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:395
Line |
 395 |          $NewImage = [System.Drawing.Graphics]::FromImage($Bitmap)
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "FromImage" with "1" argument(s): "Value cannot be
     | null. (Parameter 'image')"

InvalidOperation: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:396
Line |
 396 |  … OldImage, $(New-Object -TypeName System.Drawing.Rectangle -ArgumentLi …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.

InvalidOperation: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:415
Line |
 415 |          $Bitmap.Dispose()
     |          ~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.

InvalidOperation: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:416
Line |
 416 |          $NewImage.Dispose()
     |          ~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.

InvalidOperation: C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:417
Line |
 417 |          $OldImage.Dispose()
     |          ~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
@rashil2000
Copy link
Member

Are you on Windows 7? Please write the exact version of PowerShell and your OS.

@tripplehelix
Copy link
Author

Sorry, this is PowerShell v7.2.0-preview.9 running on Windows 11

@rashil2000
Copy link
Member

Can you try running winfetch from Windows PowerShell instead? Also, report the version of Windows PowerShell here too.

Does it show the same error?

@tripplehelix
Copy link
Author

tripplehelix commented Sep 1, 2021

With default powershell (v5.1.22000.65) I get

PS Z:\Documents> winfetch
New-Object : Exception calling ".ctor" with "1" argument(s): "Parameter is not valid."
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:390 char:21
+ ... $OldImage = New-Object -TypeName System.Drawing.Bitmap -ArgumentList  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Attempted to divide by zero.
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:391 char:9
+         $ROWS = $OldImage.Height / $OldImage.Width * $COLUMNS
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

New-Object : Exception calling ".ctor" with "2" argument(s): "Parameter is not valid."
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:394 char:19
+ ...   $Bitmap = New-Object -TypeName System.Drawing.Bitmap -ArgumentList  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Exception calling "FromImage" with "1" argument(s): "Value cannot be null.
Parameter name: image"
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:395 char:9
+         $NewImage = [System.Drawing.Graphics]::FromImage($Bitmap)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

You cannot call a method on a null-valued expression.
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:396 char:42
+ ... OldImage, $(New-Object -TypeName System.Drawing.Rectangle -ArgumentLi ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:415 char:9
+         $Bitmap.Dispose()
+         ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:416 char:9
+         $NewImage.Dispose()
+         ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\Tom\scoop\apps\winfetch\current\winfetch.ps1:417 char:9
+         $OldImage.Dispose()
+         ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

@rashil2000
Copy link
Member

image

It works fine in my virtual machine.

Can you try some other image? Or can you share the image with which you get the error?

Although the error looks like your Windows 11 build's builtin .NET framework version is not up to date. If that is the case, I believe we can't do anything other than wait for October 5 😅.

@tripplehelix
Copy link
Author

Then I found a smaller image, none of these worked.
tonk
png-clipart-mario-mario

@rashil2000
Copy link
Member

image

You can try manually downloading the latest .NET framework version and check. Other than that, since Windows 11 is currently pre-release, I can't really help.

@tripplehelix
Copy link
Author

Didn't solve it, must be missing a package. Thanks for your help anyway!

@CT3
Copy link

CT3 commented Oct 11, 2021

getting the same error on:
OS: Windows 10 Pro [64-bit]
Host: Dell Inc. XPS 13 7390
Kernel: 10.0.19043.0
Motherboard: Dell Inc. 0XVGGW
Shell: PowerShell v5.1.19041.1237
Terminal: Windows Terminal

@LittleKross
Copy link

I was able to fix this by using the full path (i.e. "C:/Users/") as opposed to the ~ shortcut to the user folder (i.e. "~/").

@rashil2000 rashil2000 changed the title Using a custom image Custom image: Exception calling ".ctor" with "1" argument(s): "Parameter is not valid." Nov 6, 2021
@Welding-Torch
Copy link

I was able to fix this by using the full path (i.e. "C:/Users/") as opposed to the ~ shortcut to the user folder (i.e. "~/").

Thank you! Been trying to figure this out for an hour

@rashil2000
Copy link
Member

@tripplehelix Can you see if this works for you as well?

@tripplehelix
Copy link
Author

@tripplehelix Can you see if this works for you as well?

I no longer have a windows pc to try this on sorry

@rashil2000
Copy link
Member

Okay, closing this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants