Assembly not found

General discussions related to using the C# Script Engine in APL+Win.

Moderators: Tech Support, phpbb_admin

Assembly not found

Postby Ajay Askoolum » September 10th, 2013, 4:38 pm

Given the following C# snippet:

using System;
using System.Diagnostics;

I tried the []cse as

Code: Select all
      'c' ⎕cse 'Init' ('System' 'System.Diagnostics')
CSE ERROR: Assembly not found.
      'c' ⎕cse 'Init' ('System' 'System.Diagnostics')
          ^

Why the error?
Ajay Askoolum
 
Posts: 635
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Assembly not found

Postby Ajay Askoolum » September 12th, 2013, 1:04 am

I can work around this error.

I am sure I read about the framework that []cse uses but I could not find the reference again. Which framework does it use? Is there a way of choosing a particular framework?
Ajay Askoolum
 
Posts: 635
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Assembly not found

Postby Tech Support » September 12th, 2013, 5:36 pm

If you question is which version of the .NET Framework is required, the answer is 4.5. This is mentioned in the
manual and in the forum topic C# Script Engine (CSE) in APL+Win Overview.

No. It is not possible to specify a different version of the .NET Framework.
Tech Support
 
Posts: 1131
Joined: February 10th, 2007, 7:33 am
Location: Rockville, MD

Re: Assembly not found

Postby joe_blaze » September 12th, 2013, 9:22 pm

Hi Ajay,

Thanks for your questions!

The 'Assembly not found' error message which your received is actually quite clear and correct. There is no .Net assembly 'System.Diagnostics.dll', so the C# compiler could not load it. The right argument to the CSE 'Init' method is a list of one or more .Net assemblies. There are .Net assemblies which contain more than one namespace and there are .Net namespaces which are spread among several .Net assemblies.

There is a material difference between referencing an assembly and adding a using statement to reduce the length of C# executable statements

The CSE 'Init' (besides creating an instance of the CSE), 'LoadAssembly' and 'LoadAssemblyByName' methods are the equivalent of adding a .Net assembly reference to a VS2012 C# project. We will emphasize this in the next version of the CSE documentation. If you create a simple C# console project in VS2012 and then attempt to add a reference to 'System.Diagnostics' you find that you cannot do it because there is no such .Net assembly. You can however insert a using System.Diagnostics; in a C# project and hence this is possible in a CSE C# script.

John already answered your question indicating that the current version of the CSE is based upon the .Net Framework 4.5 (full version).

Joe
joe_blaze
 
Posts: 381
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: Assembly not found

Postby Ajay Askoolum » September 13th, 2013, 1:32 am

John, if the download link to the code sample in this forum were updated to contain the v13.2 version, no one will fall into the scenario that I did. (Especially since it is no longer possible to install/use the previous version of CSE).

Joe, I too looked to see whether System,Diagnostics.DLL existed; as you found, it doesn't. Like you, I was inclined to see this as the reason for being unable to specify using System.Diagnostics; as part of the argument for 'Init'. However, in a C# project, you certainly CAN specify using System.Diagnostics; (see attached wmv). Indeed, you can do so in the script that becomes the argument to 'Exec'.

Therefore, a clearer explanation of 'Init' is required and you have taken this on board.

I am wondering whether 'Init' should have any arguments. I can see that 'System' enables a huge number of C# features to become available. But it would be no hardship if 'Init' simply creates and instance of [] cse and a second 'Exec' statement were required ({transpose},['']'System') before []cse did anything useful. Or, 'Init' can simply use 'System' as a default argument.

For those like me who know C#, it is easy to think that 'Init' is there to construct the block of 'using' statements; from what you say, it isn't.
Attachments
cp.wmv
(1.48 MiB) Downloaded 182 times
Ajay Askoolum
 
Posts: 635
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Assembly not found

Postby joe_blaze » September 13th, 2013, 1:55 am

Hi Ajay,

The argument to the CSE 'Init' method is not a 'using' statement.
The argument to the CSE 'Init' statement is equivalent to loading an assembly into the CSE instance.
In compiled C# world this is equivalent to adding a reference to an assembly in a C# project in VS2012.

As I stated in my prior reply: "You can however insert a using System.Diagnostics; [statement] in a C# project and hence this is [also] possible in a CSE C# script."
The argument to the CSE 'Exec', 'ExecStmt' or 'ExecFile' methods can certainly include a 'using System.Diagnostics;'.
The 'using' statement is not loading an assembly.
Loading an assembly is done using the CSE 'Init', 'LoadAssembly' or 'LoadAssemblyByName' methods.

As I am sure you know in C# a good reason for a 'using' statement is to avoid having to type in the fully-qualified name of a .Net object in the source code.

Joe
joe_blaze
 
Posts: 381
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: Assembly not found

Postby Ajay Askoolum » September 13th, 2013, 2:00 am

Got it!
Ajay Askoolum
 
Posts: 635
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom


Return to APL+Win & The C# Script Engine

Who is online

Users browsing this forum: No registered users and 1 guest

cron