0

I'm quite desperate because my C# Application won't start if I open it remotely with the PowerShell.

My application is doing some hardware access and grabs a camera picture. If I open this .exe over the VS Remote Debugger it works fine. If I open it with TeamViewer directly on the remote client, it works well.

But if I try to open my application over the PowerShell, it crashes during a bitmap operation

Bitmap newBmp = new Bitmap(ROI[2] - ROI[0], ROI[3] - ROI[1], source.PixelFormat);

with the error "Parameter is not valid!".

The values that are beeing passed are:

new Bitmap(2544 - 1, 1944 - 3, Format24bppRgb)

Why is the exe behaving completely different even though the PS doesn't anything different than simply starting a new instance of the application?

Here is how I open the executable:

PS Z:\> invoke-command -ScriptBlock { & 'C:\Users\###\Documents\Visual Studio 2015\Projects\###\Commo
n\Remote Console\bin\Debug\Remote Console.exe' -save_path=C:\Temp\Images fov=large filename=test1 setposition=200.00 Ope
ration=getpicture } -Session $remotesession

Here's stack trace:

Sure (sorry for having forgotten):

Parameter is not valid. System.Drawing at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at Utility.ImageProcessing.CopyBitmap(Bitmap source, Int32[] ROI) in C:\Users###\Documents\Visual Studio 2015 \Projects###\Common\Utility\Utility.cs:line 46 at Utility.###ServiceUtilities.ByteToImage(Int32 width, Int32 height, Byte[] imageData) in C:\Users###\Doc uments\Visual Studio 2015\Projects###Interface\Common\Utility###ServiceUtilities.cs:line 232 at Utility.###ServiceUtilities.getImage(ImageServerClient client, cameraSelect Cam, FieldType FT, Int32 WaitTime) in C:\Users###\Documents\Visual Studio 2015\Projects###Interface\Common\Utility###ServiceUtilities.cs: line 61

What the heck is going on?! ~.~

UPDATE: I found sth interesting. Any creation of a new bitmap will fail if its bigger than a defined size around 500*500*24bpp. May this be caused by some memory overflow? On the remote PC is still enough ram free (5,7Gb)!

AllDayPiano
  • 414
  • 1
  • 4
  • 20

1 Answers1

0

It is very much possible your image is not getting loaded into the memory in the given time. Try to use thread.Sleep for few seconds while your image gets loaded. That might be the issue using powershell and was getting having sufficient time when accessing using VS remotedebugger.

Also for checking. Log the Date time in millisecond before you load image and after you load image (Using remote debugger and powershell both). In case of powershell if error occurs check the time when error occurs. That way you would know how much time does it takes to load image

amit dayama
  • 3,246
  • 2
  • 17
  • 28
  • I tried System.Threading.Thread.Sleep(5000); Bitmap newBmp = new Bitmap(ROI[2] - ROI[0], ROI[3] - ROI[1], source.PixelFormat); System.Threading.Thread.Sleep(5000); but it didn't change anything. The error raises when trying to create a new bitmap. Secound sleep will never be reached. – AllDayPiano Oct 28 '15 at 11:49
  • are you disposing your bitmap when no longer in use? This error also occurs when Memoryoutofexception occurs. and is your code was build in x86 platform ? – amit dayama Oct 28 '15 at 11:57
  • The project files are built to Any CPU and are executed on both x64 computer. The Bitmap is beeing disposed if no exception will break up code execution before. – AllDayPiano Oct 28 '15 at 12:00
  • http://stackoverflow.com/questions/17419778/system-drawing-bitmapint32-int32-parameter-not-valid-in-wpf-but-not-win-forms this might help you. – amit dayama Oct 28 '15 at 12:07