DotNet Interop - Platform Bug?

james_csjames_cs Member Posts: 39
I have a very simple piece of DotNet. I am trying to create a rectangle to show on a report. The code works the first two times it is run and then fails with the message

A call to System.Drawing.Graphics.FillRectangle failed with this message: Parameter is not valid.

Variables
Name	DataType	Subtype	Length
LocalImage	DotNet	System.Drawing.Image.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
LocalImageFormat	DotNet	System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
Bitmap	DotNet	System.Drawing.Bitmap.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
Graphics	DotNet	System.Drawing.Graphics.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
Brushes	DotNet	System.Drawing.Brushes.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
InStr	InStream		

GlobalTempPicture happens to be a temporary item record (table 27) but could be a TempBLOB


Code

GlobalTempPicture.DELETEALL;

Bitmap := Bitmap.Bitmap(300,50);
LocalImage := Bitmap;
Graphics := Graphics.FromImage(LocalImage);

//This line fails - I don;'t know why
Graphics.FillRectangle(Brushes.Green,0,0,300,50);


GlobalTempPicture.Picture.CREATEINSTREAM(InStr);
LocalImage.Save(InStr,LocalImageFormat.Jpeg);
GlobalTempPicture.INSERT;

it makes no difference if I clear all the variables. I can't see that I am doing anything wrong - is this a bug?

If anyone would like the object then please let me know.

thanks in advance!

James

Best Answer

Answers

  • archer89archer89 Member Posts: 337
    dou you run clear(<dotnet variable>) at the end of your code ?
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
  • okioki Member Posts: 46
    I think, you have to create a brush first, assign the color to it and then pass it to your function.
    Hope, it helps
    Oki
  • james_csjames_cs Member Posts: 39
    I'm sorry to say that neither of these responses take the matter further. As stated - clearing the variables made no difference. Also defining the brush as a separate variable is completely equivalent to passing the Brushes enum through.

    Equivalent code works well in C# but this C/SIDE code fails after the first two successful runs. I don't know why.
  • kaspermoerchkaspermoerch Member Posts: 43
    I have been testing your code example and I get the exact same error.

    My test do show though that it sometimes crashes on the first pass.

    I will keep testing various options to see if I can get something working.
  • mdPartnerNLmdPartnerNL Member Posts: 802
    good catch :)
  • james_csjames_cs Member Posts: 39
    That's amazing - I have no idea why it works but it does work. I was under the impression that Brushes was a static and required neither to be created nor disposed. I can confirm that using the SolidBrush does not produce the same error though.

    kaspermoerch - I would be interested to understand how you figured out that the Brushes was being disposed but that is probably a different discussion!

    Many thanks for spending your time looking at this.
Sign In or Register to comment.