Posts: 1,049
Threads: 249
Joined: Jul 2022
10-28-2022, 07:22 AM
(This post was last modified: 10-28-2022, 07:27 AM by Davider.)
Hi,
The following code will have an error message after execution. But in linqpad, it can be executed successfully
This hint is a bit strange because the code doesn't need to reference the spire.pdf.dll file
System.IO.FileNotFoundException: Could not load file or assembly 'Spire.Pdf, Version=8.5.0.0, Culture=neutral, PublicKeyToken=663f351905198cb3'. 系统找不到指定的文件。
File name: 'Spire.Pdf, Version=8.5.0.0, Culture=neutral, PublicKeyToken=663f351905198cb3'
at <open "<0x10000005A>|16">line 16 in Script6.cs, Program.Main(String[] args)
// script ""
/*/ r %dll%\spire\Spire.Doc.dll; /*/
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
class Program {
public static void Main(string[] args) {
if (script.testing) {
args = new[] { @"queries\Spire\SP_多个位置加水印.linq", //代码路径
@"C:\Users\Administrator\Desktop", //args[1] 当前路径
@"日期域.docx", //args[2] 输出文件
};
}
Environment.CurrentDirectory = args[1];
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("今天的日期为: ");
Field field = paragraph.AppendField("Date", FieldType.FieldData) as Field;
field.Code = @"DATE \@" + "\"yyyy年MM月dd日 \"";
document.SaveToFile(args[2], FileFormat.Docx2013);
}
}
In the picture below, there is always a line of code, why?
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-28-2022, 08:25 AM
(This post was last modified: 10-28-2022, 10:39 AM by Gintaras.)
Better use nuget package, if Spire has it.
Or add r for all dlls used by Spire.Doc.dll, even if not used in code.
/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-28-2022, 08:28 AM
(This post was last modified: 10-28-2022, 08:31 AM by Gintaras.)
// script ""
It is how LibreAutomate recognizes forum code when pasting. And removes it when pasting. If // script "", it creates new script file. If // class "", it creates new class file. If // script "Suggested name.cs", it creates new script with the suggested name.
Also it's an useful information here. You see whether it is a script or class file, and what is its suggested name.
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-28-2022, 08:40 AM
(This post was last modified: 10-30-2022, 08:41 AM by Davider.)
The code does not require references Spire.Pdf.dll
In addition, when executing this code, it often happens that LA crashes
The crash information is as follows
Issue signature:
Problem event name: APPCRASH
Application name: Au.Task.exe
Application version: 0.0.0.0
Application timestamp: 632d553e
FAULTY MODULE NAME: KERNELBASE.dll
Faulty module version: 6.1.7601.24545
Fault module timestamp: 5e0eb6bd
Exception code: e0434352
Exception offset: 0000000000000b87d
OS version: 6.1.7601.2.1.0.256.48
Locale ID: 2052
Additional information 1: A267
Additional information 2: A2676F3E86C31732CDB231A7E6720837
Additional information 3: 00b8
Additional information 4: 00b8610e1c8e1e67039782bd26c8d064
After both dll files are referenced, the problem disappears,
But the Spire.Pdf.dll file is redundant
/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-28-2022, 09:08 AM
(This post was last modified: 10-28-2022, 10:38 AM by Gintaras.)
Spire.Doc.dll uses Spire.Pdf.dll. They are in a non-standard location, therefore .NET can't find them at run time by default. The LA compiler adds the specified path to the assembly, and at run time Au.Task.exe loads the specified dll. But it does not load the unspecified dll. I'll try to improve it in the future. Now the workaround is to specify Spire.Pdf.dll in /*/ too. Or use nuget.
To test I installed Spire.Doc Nuget package. Does not crash so far.
// script ""
/*/ nuget spire\Spire.Doc; /*/
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
if (script.testing) {
args = new[] {
@"queries\Spire\SP_多个位置加水印.linq", //代码路径
@"C:\Test", //args[1] 当前路径
@"日期域.docx", //args[2] 输出文件
};
}
Environment.CurrentDirectory = args[1];
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("今天的日期为: ");
Field field = paragraph.AppendField("Date", FieldType.FieldData) as Field;
field.Code = @"DATE \@" + "\"yyyy年MM月dd日 \"";
document.SaveToFile(args[2], FileFormat.Docx2013);
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-28-2022, 12:15 PM
(This post was last modified: 10-28-2022, 12:19 PM by Davider.)
You're right, thanks for your help!
The following code methods can all be successfully executed in Linqpad, which is very convenient for code snippet or testing purposes
But in LA, there are various limitations, not very libre, it would be better if it could also be improved
The first type of code is more generic, and I use this method now in LA
using ab.cd;
class Program
{
public static void Main(string[] args)
{
var m = "m";
}
private static void A()
{
var a = "a";
}
private static void B()
{
var b = "b";
}
}
using ab.cd;
public static void Main(string[] args)
{
var m = "m";
}
private static void A()
{
var a = "a";
}
private static void B()
{
var b = "b";
}
using ab.cd;
static void Main(string[] args)
{
var m = "m";
}
private static void A()
{
var a = "a";
}
private static void B()
{
var b = "b";
}
using ab.cd;
var m = "m";
void A()
{
var a = "a";
}
void B()
{
var b = "b";
}
using ab.cd;
void Main(string[] args)
{
var m = "m";
}
private static void A()
{
var a = "a";
}
private static void B()
{
var b = "b";
}
using ab.cd;
var m = "m";
private static void A()
{
var a = "a";
}
private static void B()
{
var b = "b";
}
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-28-2022, 12:27 PM
(This post was last modified: 10-28-2022, 12:41 PM by Gintaras.)
LibreAutomate will always support only true C#. It now is perfect for scripts. In older C# versions would always need class Program { static void Main() { ... } }.
Code pasted from somewhere can be easily edited to make it valid C#. Eg it's easy to enclose in class Program { } or remove 'private' etc. Unless you transfer hundreds of codes.
Posts: 1,049
Threads: 249
Joined: Jul 2022
The following code, after generating the exe, fails to execute with a batch command
@echo off
Script6.exe "a" "C:\Users\Administrator\Desktop" "abc.docx"
pause
// script ""
/*/ role exeProgram; outputPath %folders.Workspace%\exe\Script6; r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
class Program {
public static void Main(string[] args) {
if (script.testing) {
args = new[] { @"queries\Spire\SP_多个位置加水印.linq", //代码路径
@"C:\Users\Administrator\Desktop", //args[1] 当前路径
@"日期域.docx", //args[2] 输出文件
};
}
Environment.CurrentDirectory = args[1];
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("今天的日期为: ");
Field field = paragraph.AppendField("Date", FieldType.FieldData) as Field;
field.Code = @"DATE \@" + "\"yyyy年MM月dd日 \"";
document.SaveToFile(args[2], FileFormat.Docx2013);
}
}
Posts: 12,095
Threads: 142
Joined: Dec 2002
Posts: 1,049
Threads: 249
Joined: Jul 2022
The application failed to start because the side-by-side configuration of the application is incorrect. For more information, see the Application Event Log, or use the command-line sxstrace.exe tool. (0x36B1).
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-29-2022, 08:33 AM
(This post was last modified: 10-29-2022, 08:34 AM by Gintaras.)
I can't reproduce. From .bat and cmd the program with Spire code works well.
.bat:
@echo off
C:\path to\Script89\Script89.exe "a" "C:\Test" "test.docx"
pause
// script "Script89"
/*/ console true; role exeProgram; outputPath %folders.Workspace%\exe\Script89; r C:\Test\nuget\spire\Spire.Doc.dll; r C:\Test\nuget\spire\Spire.Pdf.dll; /*/
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
if (true) {
args = new[] {
@"queries\Spire\SP_多个位置加水印.linq", //代码路径
@"C:\Test", //args[1] 当前路径
@"日期域.docx", //args[2] 输出文件
};
}
Environment.CurrentDirectory = args[1];
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("今天的日期为: ");
Field field = paragraph.AppendField("Date", FieldType.FieldData) as Field;
field.Code = @"DATE \@" + "\"yyyy年MM月dd日 \"";
document.SaveToFile(args[2], FileFormat.Docx2013);
print.it("ok");
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-29-2022, 09:50 AM
(This post was last modified: 10-29-2022, 09:55 AM by Davider.)
Using your code is successful, Using my code is a failure, what is the problem?
Strange, now my code is okay too, GAC cache impact?
Posts: 12,095
Threads: 142
Joined: Dec 2002
Don't know. GAC not used.
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-30-2022, 05:39 AM
(This post was last modified: 10-30-2022, 08:40 AM by Davider.)
Very strange
I changed two parameters to your code( Red words below), but it didn't take effect and will still output the file with the original parameters
if (script.testing) {
args = new[] {
@"queries\Spire\SP.linq",
@" C:\Users\Administrator\Desktop",
@" www.docx", //args[2]
};
}
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-30-2022, 06:07 AM
(This post was last modified: 10-30-2022, 06:09 AM by Gintaras.)
The video shows that the folder is "C:\Test", not desktop.
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-30-2022, 07:54 AM
(This post was last modified: 10-30-2022, 07:56 AM by Davider.)
Quote:The video shows that the folder is "C:\Test", not desktop.
Yes, that's exactly the problem, The correct one should be generated on the desktop
It looks like the code was not modified or saved when executed
Before, this problem seems to have always existed
Posts: 12,095
Threads: 142
Joined: Dec 2002
Maybe does not update because the computer time is incorrect. Then click the Compile button before Run.
Posts: 1,049
Threads: 249
Joined: Jul 2022
You're right, I forgot to click the Compile button before Run.
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-30-2022, 11:20 AM
(This post was last modified: 10-30-2022, 11:25 AM by Davider.)
I don't quite understand,
QM and LA, why don't the code be precompiled before clicking the Run button? Can add an option? I often forget this at QM and LA
Posts: 12,095
Threads: 142
Joined: Dec 2002
LA compiles before Run, but only if need. It compares file times. Compiling every time would slow down script startup. In QM the same.
This feature may not work if computer time is unstable. For example, if A.exe created when computer time is 2022.10.30, then computer time changed to 2022.10.29, script edited, you click Run, and it does not recompile, because A.exe is "newer" than A.cs.
Posts: 1,049
Threads: 249
Joined: Jul 2022
Thank you for the explanation, I understand
Posts: 1,049
Threads: 249
Joined: Jul 2022
Adding the modifier public to the Program class will has some warning,
If I don't add this modifier, calling the Dll in powershell will have no effect, Should warning messages be prohibited?
Posts: 12,095
Threads: 142
Joined: Dec 2002
Editor just reminds to write documentation. Ignore it.
Posts: 1,049
Threads: 249
Joined: Jul 2022
Thank you for the reminder
my English is not very good, just read the translation of the warning message and understand what is going on
The trigger linked below doesn't seem to have an effect, Unable to get text in the warning window,
https://www.libreautomate.com/forum/show...8#pid35948
Posts: 1,049
Threads: 249
Joined: Jul 2022
When I use a non-English input method, there is a blank window:
Suggestion:
When using English input methods, this list is displayed, other input methods are not displayed, and this situation persists
Posts: 1,049
Threads: 249
Joined: Jul 2022
11-10-2022, 11:06 AM
(This post was last modified: 11-10-2022, 11:09 AM by Davider.)
How generate a XML Documentation file for the Dll file?
Posts: 12,095
Threads: 142
Joined: Dec 2002
Can generate xml file only for libraries (class file role classLibrary). In Properties check the checkbox.
Posts: 1,049
Threads: 249
Joined: Jul 2022
Posts: 12,095
Threads: 142
Joined: Dec 2002
11-13-2022, 02:58 PM
(This post was last modified: 11-13-2022, 03:47 PM by Gintaras.)
Blank window - will be fixed in next program version.
Warning window text can be selected, copied and then translated. Also the new script version (attached) supports such windows without selecting.
https://www.libreautomate.com/forum/show...p?tid=7305
Posts: 1,049
Threads: 249
Joined: Jul 2022
11-13-2022, 11:51 PM
(This post was last modified: 11-14-2022, 12:00 AM by Davider.)
thanks!
When I select the text, execute the code, and translate the line of text
|