meenu - Thursday, April 4, 2013 9:05 AM:
Hi,
I am developing some C# Methods, but every method is throwing two common errors. I tried with simple logic but result is same. The errors I have been facing are :
1)Line number 1, Error Number: CS1513, } expected 2)Line number 51, Error Number: CS1022, Type or namespace definition, or end-of-file expected .
Code ends at Line number 12, but the error is at line 51. I' m trying with simple code like:
using System;
class Program
{
static void Main(string[] args)
{
int x; x = 1;
int y; y = 3;
int z; z = x * y;
Console.WriteLine("The value of z is " + z);
}
}
If I run the code(this sample code and Actual code that I have been working on) in VisualStudio, it is not throwing any error there. Why I' m getting these errors? Help me.
Thank you, M.K
zahar - Thursday, April 4, 2013 10:27 AM:
Your code need to be:
int x; x = 1;
int y; y = 3;
int z; z = x * y;
Console.WriteLine("The value of z is " + z);
gks by TSI - Friday, April 5, 2013 2:04 AM:
Your code is embeded in a template found in method-config.xml
That's why "using" is not an allowed keyword and throws all those errrors.
meenu - Friday, April 5, 2013 2:30 AM:
Thanks Zahar and gks,
But I need using the Classes. How can I use Classes inside Aras
Thanks, M.K
zahar - Friday, April 5, 2013 3:41 AM:
My answer was relevant to your example only. Like gks told you the code of method is embedded in class structure as defined in method-config.xml file (you can find it in <Innovator>server folder.
By updating this xml you can define as much "using" as you want (copy dlls to bin folder that you want to "use")
about class structure in method you can do it by using something like this:
YourClassName varibleName = new YourClassName();
} //this will close method function that aras includes your code in
class YourClassName
{
public void YourClassName() {
}
public void WriteToConsole() {
int x; x = 1;
int y; y = 3;
int z; z = x * y;
Console.WriteLine("The value of z is " + z);
}
// Don't close your class with "}" because every code in method will be closed by Aras
meenu - Friday, April 5, 2013 5:19 AM:
Zahar, I removed the Directives from code and added to Config file, now I' m getting an error states that:
Line number -4, Error Number: CS0161, 'PKG_103F8FCD676568AE7A7F63B7358C4F31.ItemMethod.methodCode()': not all code paths return a value
Thanks.
zahar - Friday, April 5, 2013 5:29 AM:
Add to the start of the method following code:
RequestSignatureDoc.Main(); //this will call your main function in your class
return this; //all aras methods must return item or result item (check programmer guide pdf for basic aras programming)
meenu - Friday, April 5, 2013 6:11 AM:
Thank you Zahar, It worked after adding the above two lines, no more errors.
meenu - Tuesday, April 16, 2013 2:18 AM:
Hi,
Where can I find the output of print statements? Console.WriteLine("Get Console View Result: " + responseText); . This will write the result but after running the method I' m getting a page with just 'Method name' and '<Result>' tag.
Brian - Tuesday, April 16, 2013 10:40 PM:
HI MK,
You are not running a console application so you can't really use Console.Write(...
If you want to be able to see a response then instead of returning "this" you can return a newResult("string to return");
To do this you will need to retrieve an Innovator object to call the newResult from.
Depending on where the server method is being called the access to the Innovator item might be different.
example:
From an Action where the "target" is "Window".
Innovator inn = this.getInnovator();
// your code goes here.
return inn.newResult("string to return here");
This will show you the results of the method in the Window that is displaying after the method runs.
Also because of the environment and template you are writing your code within there is no need for you to define a "public class" for most simple code.
In your example you could dispense with the class definition and just write the "main" method code directly in the code window since it is not calling other methods or classes.
There is no issue with using classes but you also shouldn't need to define a public static main() method as an entry point.
Hope this helps,
Brian.
meenu - Thursday, April 18, 2013 2:06 AM:
Thanks Brian,
Now I' m not using the class, But I' m starting with public static Main() method , what is wrong in defining this?What would be the best way of defining this method?
Is there a way to use 'Innovator class' inside a method(inside Main())? Where can I find some help on defining Methods and Classes in Aras programming. Programmers Guide is not having examples on this.
Thank You,M.K
gks by TSI - Thursday, April 18, 2013 2:21 AM:
www.aras.com/.../DocumentView.aspx
Chapter 4. is all about methods, clientside and serverside.
Depending on the type of your method, server or client, and the way it is called (action, aml or event) not all return types (error, result, normal Item) make sense.
Brian - Thursday, April 18, 2013 2:39 AM:
Hi MK,
I have added a WIKI page http://www.aras.comhttp://www.aras.com/Community/wikis/kb/using-classes-inside-server-methods.aspx that describes a bit about using classes inside Innovator server methods.
Hope this helps,
Brian.
meenu - Thursday, April 25, 2013 6:08 AM:
Thank you all,
Now I' m able to write methods by following the Aras class structure as explained in the link provided by Brian last week. But still facing some problems while following the structure.
For ex:
Program.Main(); return this; }
public static class Program {
public static void MethodName() ///this is extension method { //method code// }
public static void Main() { ///Main method code ///Here the extension method will be called
}//End Main()
When I run the code it is throwing an error says: Extension methods must be defined in a top level static class;'Program' is a nested class
Why class 'Program' became nested class here? As per VS it is top level class not a nested class.
Thank you, M.K
gks by TSI - Thursday, April 25, 2013 7:01 AM:
"... when the method is compiled it is decorated with class and using definitions automatically according to the template and defined in the "method-config.xml" file located under the Innovator installation directory (Aras/Innovator/Server/method-config.xml)...."
This fragment is from www.aras.comhttp:/.../using-classes-inside-server-methods.aspx and it explains why your class becomes a nested class.
You can not copy and paste your code from VS into the aras editor!
Try this:
Main();
return this;
}
public static void MethodName() {
//method code
}
public static void Main() {
//Main method code
//Here the extension method will be called
}
This will not work in VS, but it will work as aras method
meenu - Thursday, April 25, 2013 8:00 AM:
Yeah I followed the same structure and I have not used the Class declaration in my other methods, but here in this method I' m using an 'Extension method', which should be defined under a Static class and it should be a top level one.
But in the method-config file no static classes are defined , when I run the code only a public class is being added and error says: Extension methods must be defined in a non-generic static class '
Please recommend a solution to this. Any changes need to be done to method-config file?
Thank you, M.K