Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prompt for references error
#1
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)
 
Code:
Copy      Help
// 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?
[Image: c.png]
#2
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.
 
Code:
Copy      Help
/*/ r %dll%\spire\Spire.Doc.dll; r %dll%\spire\Spire.Pdf.dll; /*/
#3
// 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.
#4
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; /*/
#5
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.
 
Code:
Copy      Help
// 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);
#6
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


Code:
Copy      Help
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";
    }
}
 
Code:
Copy      Help
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";
}
 
Code:
Copy      Help
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";
}
 
Code:
Copy      Help
using ab.cd;


var m = "m";


void A()
{
    var a = "a";
}

void B()
{
    var b = "b";
}
 
Code:
Copy      Help
using ab.cd;

void Main(string[] args)
{
    var m = "m";
}

private static void A()
{
    var a = "a";
}

private static void B()
{
    var b = "b";
}
Code:
Copy      Help
using ab.cd;


var m = "m";


private static void A()
{
    var a = "a";
}

private static void B()
{
    var b = "b";
}
#7
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.
#8
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


Code:
Copy      Help
// 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);
    }
}
#9
What error is displayed?
#10
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).
#11
I can't reproduce. From .bat and cmd the program with Spire code works well.

.bat:
Code:
Copy      Help
@echo off
C:\path to\Script89\Script89.exe "a" "C:\Test" "test.docx"
pause
 
Code:
Copy      Help
// 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");
#12
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?
#13
Don't know. GAC not used.
#14
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] 
    };
}
#15
The video shows that the folder is "C:\Test", not desktop.
#16
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
#17
Maybe does not update because the computer time is incorrect. Then click the Compile button before Run.
#18
You're right, I forgot to click the  Compile button before Run. Big Grin
#19
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  Smile
#20
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.
#21
Thank you for the explanation, I understand
#22
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?

[Image: abc.gif]
#23
Editor just reminds to write documentation. Ignore it.
#24
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
#25
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

[Image: abc.gif]
#26
How generate a XML Documentation file for the Dll file?
#27
Can generate xml file only for libraries (class file role classLibrary). In Properties check the checkbox.
#28
thanks! works well
#29
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
#30
thanks!
When I select the text, execute the code, and translate the line of text
[Image: dd.gif]


Forum Jump:


Users browsing this thread: 1 Guest(s)