Possibly error message when starting program with missing included DLL

Have some feedback and input to share?
Don't be shy and drop us a note. We want to hear from you and strive to make our site better and more user friendly for our guests and members a like.
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Possibly error message when starting program with missing included DLL

Post by wriedmann »

Hi Robert,
thank you very much!
XIDE seems to not have the option "Prefix classes with Default Namespace" or it is called differently.
My Startup class is called

Code: Select all

class XStartupCode

[STAThreadAttribute];
static method Start as void
	Start()
	return
end class
The executable is "DictEdit.exe", and therefore I would assume the fully specified entry point class name is
"DictEdit.Exe.XStartupCode".
But the compiler says

Code: Select all

error XS1555: Could not find 'DictEdit.Exe.StartupCode' specified for Start function
But if I remove all namespace indications from the commandline letting

Code: Select all

-main:XStartupCode
the compiler says

Code: Select all

error XS1558: 'XStartupCode' does not have a suitable static 'Start' function	6,1	Start.prg	XStartupCode:XStartupCode
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4551
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Possibly error message when starting program with missing included DLL

Post by robert »

Wolfgang,
The executable is "DictEdit.exe", and therefore I would assume the fully specified entry point class name is
"DictEdit.Exe.XStartupCode".
That is an incorrect assumption. The only namespace that is derived from the assembly name is the namespace from the Functions class.
Your own classes are in a namespace that you define in code with a begin namespace ... end namespace pair:

Code: Select all

begin namespace DictEdit
class XStartupCode
.
.
.
end class
end namespace
Without this the classes are in the global namespace (which actually means 'no namespace').

If you do not specify your own namespace, then you can use the compiler option that I mentioned.
However, you are right: XIDE does not have that option.
You have to add the compiler option /ns:MyNameSpace to the additional switches textbox, to achieve this.

Btw. for a future version of X# we are planning to add the Filescoped Namespace Declaration to the language (C# 12 has that too)
That would change the code above to

Code: Select all

namespace DictEdit
class XStartupCode
.
.
.
end class
All classes in the file following the namespace declaration would be placed in the namespace. So you do not need a begin namespace .. end namespace pair.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Possibly error message when starting program with missing included DLL

Post by wriedmann »

Hi Robert,
I think I have found the solution:
There is no need to specify the namespace, when the entry point class is indicated without one:

Code: Select all

-main:XStartupCode
The last problem is that the Start function has to be defined as follows:

Code: Select all

[STAThreadAttribute];
static method Start( Args as string[] ) as void
I will try to document that somewhere in my wiki, otherwise the messages may go lost over time.
Thank you very much for all your help!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4949
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Possibly error message when starting program with missing included DLL

Post by Chris »

Guys,

Sorry for not responding earlier, finally here we have rain and the temp dropped, so I could sleep a bit more today :)

In XIDE, the option in the app properties named "Global Namespace" maps directly to the /ns compiler option, so no need to specify it directly in the extra options. There's no extra "Prefix classes with global namespace" option, if you enter something in the Global Namespace option, then it is always passed to the compiler.

Wolfgang, no, it's not necessary to have this particular definition for Start for it to work. A simple

STATIC METHOD Start() AS VOID

works as well.

I suspect it didn't work for you earlier, because of the default namespace confusion. If it still doesn't work, can you please post the .xiaef to have a look?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Possibly error message when starting program with missing included DLL

Post by wriedmann »

Hi Chris,
I have added that special class and entry point only to be able to track missing references.
The added startup class is as follows:

Code: Select all

class XStartupCode

[STAThreadAttribute];
static method Start( Args as string[] ) as void
	local oSB as System.Text.StringBuilder

	try

	Start()

	catch oEx as Exception

	AllocConsole()
	oSB := System.Text.StringBuilder{}
	Output( oSB, "An unhandled exception has occurred" )
	Output( oSB, "===================================" )
	do while oEx != null
		Output( oSB, "Exception: " + oEx:Message )
		Output( oSB, "Callstack:")
		Output( oSB, oEx:StackTrace )
		Output( oSB, "" )
		oEx := oEx:InnerException
	enddo
	Output( oSB, "===================================" )
	Output( oSB, "Press return to close the application" )
	XStartupCode.Wait()
	System.IO.File.AppendAllText( System.IO.Path.Combine( AppDomain.CurrentDomain:BaseDirectory, "ApplicationError.log" ), oSB:ToString() )

	end try

	return

static method Output( oSB as System.Text.StringBuilder, cText as string ) as void

	oSB:AppendLine( cText )
	Console.WriteLine( cText )

	return

static method Wait() as void

	Console.ReadLine()

	return

[DllImport("kernel32.dll", SetLastError := true)];
[return: MarshalAs(UnmanagedType.Bool)];
static extern method AllocConsole() as logic

[DllImport("user32.dll", CharSet := CharSet.Ansi)];
static method MessageBox(hwnd as IntPtr, lpText as string, lpCaption as string, uType as dword) as int pascal

end class
If the transporter or even better the compiler can do that alone, it would be even better.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4949
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Possibly error message when starting program with missing included DLL

Post by Chris »

Hi Wolfgang,

OK, I understand, I just pointed out that you do not need to use this special definition for it to work. Also this is supported as an app entry method:

Code: Select all

CLASS XStartupCode
STATIC METHOD Start() AS VOID
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Possibly error message when starting program with missing included DLL

Post by wriedmann »

Hi Chris,
unfortunately the parameters were needed to make it work with the -main compiler option.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4949
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Possibly error message when starting program with missing included DLL

Post by Chris »

Hi Wolfgang,

They don't, I have it working here without the parameters. Can you please post the .xiaef that gives you the error? Maybe I'm not doing something else that you have in your app.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Possibly error message when starting program with missing included DLL

Post by wriedmann »

Hi Chris,
sorry, it took me a while to understand why your code works and why mine does not worked.
If you have an application in Core dialect, it works without parameters. But if your application is in VO dialect, it requires the parameters.
Please look at this sample (migrated VO console application):
StartupExceptionConsole.zip
(2.24 KiB) Downloaded 45 times
whereas this sample works without parameters (Windows Forms application):
StartupExceptionTester.zip
(2.64 KiB) Downloaded 40 times
The purpose of this construct is to display errors when a runtime DLL is missing.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3773
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Possibly error message when starting program with missing included DLL

Post by wriedmann »

Hi Robert,
I have copied your message about the namespace to my wiki together with the source reference:
https://docs.xsharp.it/doku.php?id=name ... plications
If you think there should be added something please let me know.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply