Missing from Assembly Error Using Invoke Code

Hi all,

Wondering if someone has seen this error. I’m using Invoke Code to convert a text file to pdf using Spire.PDF. Weird thing is it actually worked a few times and then started throwing this error.

If I’m reading this right, it seems to be an issue with fowarding RectangeF in System.Drawing 2.0.0.0 to version 4.0.0.0 but issues finding that.

System.Drawing is in the Imported Namespaces, I’ve tried reordering in xaml file, .net 4.8 is installed, not sure what else to try.

Here’s the error.

Source: Invoke code

Message: No compiled code to run
error BC31424: Type 'System.Drawing.RectangleF' in assembly 'netstandard, Version=2.0.0.0, 
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' has been forwarded to assembly 
'System.Drawing'. Either a reference to 'System.Drawing' is missing from your project or the type 
'System.Drawing.RectangleF' is missing from assembly 'System.Drawing'. At line 14

error BC30652: Reference required to assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a' containing the type 'System.Drawing.PointF'. Add one to your 
project. At line 16

Thanks.

Troy

Hi @tmays

have you tried this based on macro??

Thanks
Ashwin S

Hi @AshwinS2

Not sure I understand what you mean by “tried based on macro”. Here’s the Invoke Code but seem more of an issue with the System.Drawing namespace.

Dim text As String = File.ReadAllText("c:\temp\TRN1410.PRT")
Dim doc As New PdfDocument()
Dim section As PdfSection = doc.Sections.Add()
Dim page As PdfPageBase = section.Pages.Add()
Dim font As New PdfFont(PdfFontFamily.Helvetica, 11)
Dim format As New PdfStringFormat()
format.LineSpacing = 20.0F
Dim brush As PdfBrush = PdfBrushes.Black
Dim textWidget As New PdfTextWidget(text, font, brush)
Dim y As Single = 0
Dim textLayout As New PdfTextLayout()
textLayout.Break = PdfLayoutBreakType.FitPage
textLayout.Layout = PdfLayoutType.Paginate
Dim bounds As New RectangleF(New PointF(0, y), page.Canvas.ClientSize)
textWidget.StringFormat = format
textWidget.Draw(page, bounds, textLayout)
doc.SaveToFile("c:\temp\TxtToPDf.pdf", FileFormat.PDF)

If you want to save a txt as pdf why you are not using the Activity Export to PDF instead ?

Hey @carmen

That does work but the file has specific formatting and would have to open in Word and make those changes. Prefer to avoid that.

Thanks for the idea though.

Troy

You dont need to open word to save as pdf. If you need to do any change to your document you could make your changes in your way and then save it as pdf without open word. Just saying to keep it simple.

@carmen

I didn’t mean to dismiss your suggestion outright and am looking closer now. I can create a Word template with my formatting, use append text activity, Export to PDF activity, blow away the changes, and then exit. Of course this all has to be wrapped in the Word Application Scope.

This does open Word in the background. The Word scope doesn’t have a “visible” setting like Excel.

Of course I may be missing something so please expand if I have something wrong. …and I may use this method just to get it done. :slight_smile:

Thanks again.

I never done that before, just was an idea, but I guess you are in a good track. If that works for you let us now. I always try to keep the things simple that’s all and I try to look for the activities that uipath have before to write code.

Hi @tmays
I am faceing the same problem,have you got the solution?
I think maybe the invoke code activity doesn’t surpport some VB.NET types.
Now I use the System.Drawing.Point, the same error happene.

I’m trying to do the same String to PDF convert using Spire.PDF library and getting the same error. Were you able to solve the issue or find another way to convert string to pdf?