Neo.ApplicationFramework "The name ... does not exist in the current context" - c#

I'm dabbling in C# to write some scripts in what is otherwise a graphical machine interface programming environment (Beijer's iX Developer). The HMI is monitoring 'tags' (variables) in a PLC (programmable logic controller).
When tag Controller1_M18 turns on I want to print a report and then reset the tag. This code I'm putting in the Tags Script module is giving me error "The name 'PrintReport' does not exist in the current context". Can anyone give me guidance in fixing it?
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using Neo.ApplicationFramework.Tools.Reporting;
public partial class Report_Functions
{
void Controller1_M18_ValueOn(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
// Print the report.
PrintReport("BatchReport1");
// Reset the tag.
Globals.Tags.Controller1_M18.ResetTag();
}
}
}
The sparse scripting help file gives the information
Namespace: Neo.ApplicationFramework.Tools.Reporting
Assembly: ToolsCF (in ToolsCF.dll) Version: 2.15.5714.0
Syntax
public void PrintReport(
string reportName
)
ToolsCF.dll is present in the application folder along with all the others.

The method you are attempting to call, PrintReport simply doesn't exist in the class you have created. Either you have copy pasted this code from somewhere and missed that out or you are trying to reference a method in a different class. It's impossible to tell any more than this from the limited information provided.

Neo.ApplicationFramework.Generated.Globals.Reports.PrintReport("BatchReport1");

Related

Unable to get Source Generator to do anything

I've been wrestling with Source Generators but there's a lack of tutorials and information that are hurting.
I want to generate some C# classes from a database. Using a T4 template to do this is difficult and problematic, because of issues I'm having with using SQL in T4 templates and similar.
The description of Source Generator is that "The generator can create new C# source files on the fly that are added to the user's compilation. In this way, you have code that runs during compilation. It inspects your program to produce additional source files that are compiled together with the rest of your code." which seems to match what I want.
This seems significantly more promising.
I've created a project, and put a [Generator] into it using this tutorial.
Full source:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace x
{
[Generator]
internal class TestGenerator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
File.Create(#"C:\temp\ITRUNS.TXT");
var sourceBuilder = new StringBuilder(#"
using System;
namespace HelloWorldGenerated
{
public static class HelloWorld
{
public static void SayHello()
{
Console.WriteLine(""Hello from generated code!"");
Console.WriteLine(""The following syntax trees existed in the compilation that created this program:"");
");
Debugger.Launch();
// using the context, get a list of syntax trees in the users compilation
var syntaxTrees = context.Compilation.SyntaxTrees;
// add the filepath of each tree to the class we're building
foreach (SyntaxTree tree in syntaxTrees)
{
sourceBuilder.AppendLine($#"Console.WriteLine(#"" - {tree.FilePath}"");");
}
// finish creating the source to inject
sourceBuilder.Append(#"
}
}
}");
// inject the created source into the users compilation
context.AddSource("helloWorldGenerator", SourceText.From(sourceBuilder.ToString(), Encoding.UTF8));
}
public void Initialize(GeneratorInitializationContext context)
{
}
}
}
I want this to run when I build the solution and create some .cs files
However, it does not run. I put some code in the execute method to create a file, and it does not create the file.
The tutorial says:
Add the source generator from a project as an analyzer and add preview to the LangVersion to the project file like this:
I don't really know what this means. Which project? I tried to download the samples as suggested, but I can't get them to build.
When I examine the code, it's quite hard to understand what they've done that is different.
And what they say in the tutorial about adding the analyzer, doesn't seem to present anywhere in the sample code!
I tried adding the project reference in the csproj that it said to add, however that didn't work - it did create an item within Analyzers but it just has a red - and says 'Ignored' on the tooltip.
I honestly don't know what else I can do to figure out how to get this to work.
I also don't know for sure if it will do what I want - autogenerate a bunch of .cs files with code in that I can use.
I'm going to give it one more go then I'll just write a console application to do it manually instead. Any ideas are welcome.

"Name 'Process' does not exist in current context" error in console app

I'm trying to use the Process class but it gives me this compiler error every time I do
The name 'Process' does not exist in the current context
I've already added using System.Diagnostics; at the top of my code but I still get this error. Autocomplete wont even recognize the class.
Hear is the code. I've only included the Main method because the rest of the code has nothing to do with the error.
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
public class MainClass
{
static void Main()
{
AIRuntime adam = new AIRuntime("Adam", false);
adam.AIUpdate();
Process.Start(adam.directory); //adam.directory is just a string
}
}
My IDE is Xamarin Studio if it matters.
After web searching and attempts, I found the problem.
To fix this, I manually add a reference to System in my project options instead of just typing using System;. I also need to keep using System.Diagnostics; at the top. It's all in the picture below
Thanks guys for trying to help

linking a new windows form with an existing project in c#

I have a c# problem. I have created a project called 'classproject' and I have added several forms to project successfully and successfully ran the program, but there is this other windows form that I just added and when I double-clicked on the form, it took me to the code view and brought out this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class demo : Form
{
public demo()
{
InitializeComponent();
}
private void demo_Load(object sender, EventArgs e)
{
}
}
}
Now, my challenge is that the name of the project is meant to show by default after the namespace as in "namespace classproject" instead of "namespace WindowsFormsApplication1". Please can anyone help me out, what am I meant to do because have tried everything possible. Even if I change the name myself its still going to flag error... someone please help me as soon as possible.
I'm not sure exactly what your issue is. If you change the namespace manually in the code to classproject it should be fine. What error are you talking about? You would also need to change the designer code file as well (probably called demo.Designer.cs).
Just a side note as well. Standard naming convention for C# is to use Pascal-case (as in ClassProject).
You must change namespace in ALL files that was generated by Visual Studio. You can do it manually, or just set cursor on "WindowsFormsApplication1", press F2 and enter new name.
Optionaly you can also change namespace in project properties on Application tab - then all new files added to project will also have namespace that you set there.

One web application, two namespaces

I have one web application with two projects:
Project "Website"
Using CMS;
namespace Web
{
}
Project "CMS"
namespace CMS
{
public class Functions
{
}
}
Then I want to be able to use CMS.Functions.MyMethod() inside Website.Web.
Im having some problem with this.. Inside the "Website" project I have added "CMS" as a reference and I have also added Using CMS; and even tho the intellisense picks up CMS.Functions I get an error! The word CMS gets underlined blue and I get the message:
The name 'CMS' does not exist in the current context
What am I missing out? Its so weird becuase I can write CMS.Functions and the "Functions" part comes up in the intellisense but when I finish the line the word CMS gets underlined blue and I get the error even tho I got a reference and a Using statement.
From the sound of it, you want to make your Functions class methods to be static
namespace CMS
{
public class Functions
{
public static void MyMethod(){
//do stuff
}
}
}
The most likely cause is that you have not added a reference to the CMS project to your main project. That is the only time that I get the exception about the name not existing in the current context.

How to write a hello world add-in for Win 7 Media Center

I want to write a simple hello world add in for Media Center on Windows 7, but I am having problems finding up to date functional documentation. I found this page: http://blogs.msdn.com/b/mcreasy/archive/2004/10/12/241449.aspx which looks to be exactly what I need. I implemented it and some of the interfaces it references are marked as obsolete, and even so when I try to launch it in media center is just pops up a dialog saying "unable to launch addin"
I updated the namespace interfaces from using Microsoft.MediaCenter.AddIn to using Microsoft.MediaCenter.Hosting which looks to be the up to date namespace according to the sdk docs, but I still have the same problem.
registering the assembly with the gac and with RegisterMCEApp both are successful, and I have unregistered and registered from both places in between builds.
I strongly signed the assembly with a .snk file and got the public key token to update the registration.xml
Can anyone either tell me what I am doing wrong or direct me to some up to date tutorial /docs?
Here is the little bit of code I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.MediaCenter.Hosting;
namespace MCPluginTakeTwo
{
public class HelloWorldAddIn: MarshalByRefObject, IAddInModule, IAddInEntryPoint
{
public void Initialize(Dictionary<string, object> appInfo, Dictionary<string, object> entryPointInfo)
{
}
public void Uninitialize()
{
}
public void Launch(AddInHost host)
{
}
}
}
Maybe looking at some open source mc plugins would help.
Here's another getting started tutorial, with some tips for getting started with Visual Studio 2010 (because the SDK only comes with VS 2008 templates).
http://david.gardiner.net.au/2010/10/writing-media-center-application-in.html

Categories

Resources