I installed flawless this package:
https://www.nuget.org/packages/ini-parser/
https://github.com/rickyah/ini-parser
It shows up in my project dependencies and i am using the directive suggested
by the author:
using IniParser;
using IniParser.Model;
But the "code" is not seen in my Form1.cs where i put the directive ?
Error CS0246.
I am a beginner so you know.
you may need to understand how to apply [using][1] and differences between Directive and static Directive and normally diagnostic with fully qualified type name to understand better.
I installed the nuget and put the using directives in and could instantly use it
namespace WindowsFormsApp1
{
using System.Windows.Forms;
using IniParser;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var parser = new FileIniDataParser();
var data = parser.ReadFile("Configuration.ini");
var useFullScreenStr = data["UI"]["fullscreen"];
var useFullScreen = bool.Parse(useFullScreenStr);
data["UI"]["fullscreen"] = "true";
parser.WriteFile("Configuration.ini", data);
}
}
}
It was an easy solution. I had to refresh the library or package dependencies and it instantly found it. Thank you for the answers.
Related
I have am developing in Unity 2019.2.3f1. I am trying to write a script that can Customize project files created by VSTU. In case the link ever gets removed, I have included a script very similar to the one from the link.
#if ENABLE_VSTU
using System.IO;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
using SyntaxTree.VisualStudio.Unity.Bridge;
[InitializeOnLoad]
public class ProjectFileHook
{
private class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
static ProjectFileHook()
{
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
// parse the document and make some changes
XDocument document = XDocument.Parse(content);
document.Root?.Add(new XComment("FIX ME"));
// save the changes using the Utf8StringWriter
Utf8StringWriter str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
};
}
}
#endif
The issue is, using SyntaxTree.VisualStudio.Unity.Bridge; fails to compile due to the error error CS0246: The type or namespace name 'SyntaxTree' could not be found (are you missing a using directive or an assembly reference?).
I have checked both Unity and Visual Studio that the Visual Studio Tools for Unity are installed and enabled.
Why is the code failing to compile? Am I missing something that is preventing it from compiling?
Just incase anyone else has this issue.
This issue was being caused by the scripts position. The script has to be under the Editor folder, otherwise the script won't work as expected.
Credits to therealjohn for pointing it out here.
My code there is a errors like
"The type or namespace name 'ChannelData' could not be found (are you missing a using directive or an assembly reference?)"
How I correct this.please give your help.
class ProcessCSV
{
public static string dateFormatString = "dd/MM/yyyy HH:mm:ss";
private string prefix = "";
ChannelData[] channelData = new ChannelData[4];
private ChannelData[] loadChannelData(string[] valuesInCsvLine)
{
channelData[0] = new ChannelData();
channelData[1] = new ChannelData();
channelData[2] = new ChannelData();
channelData[3] = new ChannelData();
}
}
There is .Net framework incompatibility issue between your projects. The project consisting of type ChannelData can be of different version than that of your current project.
Sometimes it is also a client profiling issue. Make sure that both the projects are using the same .Net framework.
If you are using ChannelData from external assembly or dll, then you can right click on ChannelData and just goto definition. It will show you the version and you can match it with your current project (if it's convenient to you).
But if you are not having the above issues then sometimes cleaning and rebuilding your solution simply helps. You can also restart your visual studio.
Hope it helps you.
This might be a C#-noob question...
Assume I have the following CLI/C++ header:
namespace DotNet {
namespace V1 {
namespace X {
public ref class AClass {
public:
AClass() {}
void foo() {}
static void bar() {}
};
}
}
}
Then from C# I do the following:
using DotNet;
V1.X.AClass a = new V1.X.AClass();
I get:
Program.cs(18,7): error CS0246: The type or namespace name 'V1' could
not be found (are you missing a using directive or an assembly
reference?)
Same with:
using DotNet.V1;
X.AClass a = new X.AClass();
Program.cs(18,7): error CS0246: The type or namespace name 'X' could
not be found (are you missing a using directive or an assembly
reference?)
What works is:
DotNet.V1.X.AClass a = new DotNet.V1.X.AClass();
Or
using DotNet.V1.X;
AClass a = new AClass();
So either I have to use the full namespace path, or I have to open all of the path to access the class. Is there anything I can do about this?
I would like to be able to open only a part of it.
So either I have to use the full namespace path, or I have to open all of the path to access the class.
Yes.
Is there anything I can do about this?
Not that I'm aware of. Why would you not just want a using directive for the whole namespace? Isn't that the simplest approach?
Note that this has nothing to do with C++/CLI. The same is true whatever the source language is - so you can see it with C# as well:
namespace DotNet.V1.X
{
public class AClass {}
}
As Jon Skeet stated you have to include the full namespace in either the using statement or each time you reference it in code. I recommend just placing the full namespace in the using statement.
You can, however, achieve that syntax with a using alias, but it does not add anything of value outside of syntax.
using V1 = DotNet.V1;
...
V1.X.AClass a = new V1.X.AClass();
Also if you are using C# version 3.0 or higher the var keyword will only require you type out the full namespace on the right side of the assignment.
var a = new DotNet.V1.X.AClass();
Okay, I'm a newbie in C# but I need to create a simple GUI, but I don't have Visual Studio (I use Geany and Mono).
The problem is, when I tried the following code that I found by Google:
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
public class FirstForm : Form
{
private Container components;
private Label howdyLabel;
public FirstForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
components = new Container ();
howdyLabel = new Label ();
howdyLabel.Location = new Point (12, 116);
howdyLabel.Text = "Howdy, Partner!";
howdyLabel.Size = new Size (267, 40);
howdyLabel.AutoSize = true;
howdyLabel.Font = new Font (
"Microsoft Sans Serif",
26, System.
Drawing.FontStyle.Bold);
howdyLabel.TabIndex = 0;
howdyLabel.Anchor = AnchorStyles.None;
howdyLabel.TextAlign = ContentAlignment.MiddleCenter;
Text = "First Form";
Controls.Add (howdyLabel);
}
public static void Main()
{
Application.Run(new FirstForm());
}
}
I just get these errors when trying to compile:
C:\C#\test2.cs(2,14): error CS0234: The type or namespace name 'Windows' does not exist in the namespace 'System'. Are you missing an assembly reference?
C:\C#\test2.cs(4,14): error CS0234: The type or namespace name 'Drawing' does not exist in the namespace 'System'. Are you missing an assembly reference?
C:\C#\test2.cs(9,11): error CS0234: The type or namespace name 'Label' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 3 error(s), 0 warnings
I downloaded both DLL's, but I don't know what to do next.
Link to the code: http://www.informit.com/articles/article.aspx?p=27316
You're using the Microsoft WinForms UI library, which Mono does not include.
You need to use a Mono-compatible UI library, such as GTK#.
You can also use the Mono port of WinForms.
You are using WinForm on mono, maybe will be better use GTK#, however if you want use WinForms on mono it is possible. Take a look at this documentation for more information .
You have to use gmcs in this way to compile your program :
gmcs Program.cs -r:System.Windows.Forms.dll
I created a solution called Foo.
Added a class library called Foo.Common
Added a console app to call the library code from called ConsoleApp.
I referenced the Foo.Common from ConsoleApp and typed :
using Foo.Common;
public class Program
{
CommonClass c = new CommonClass();
static void Main(string[] args)
{
}
}
and get this back :
Error 1 The type or namespace name '**Foo**' could not be found (are you missing a using directive or an assembly reference?) Z:\Foo\Solution1\ConsoleApplication1\Program.cs 3 11 ConsoleApplication1
Why am i getting this?
what s going on?
Make sure that
The ConsoleApp project has a reference to the Foo.Common project (do not browse for Foo.Common.dll),
the file contains a using directive for the namespace in which CommonClass is declared, and
CommonClass is declared as public.
So your files should look like this:
CommonClass.cs in Foo.Common project:
namespace Foo.Common
{
public class CommonClass
{
public CommonClass()
{
}
}
}
Program.cs in ConsoleApp project:
using Foo.Common;
namespace ConsoleApp
{
public class Program
{
public static void Main()
{
CommonClass x = new CommonClass();
}
}
}
Ensure that under your project settings, the target framework is set as .NET Framework 4 and not .NET Framework 4 Client Profile. I got this same behavior when it was set to Client Profile and it was fixes as soon as I set it to just the regular .NET Framework 4.
Right Click on the new console app solution/project and Add Reference and add the project that contains the Foo namespace
Did you add a reference to the library? Look under "References" in the console project. If its not there, you need to add it.
I posted this as a comment, but I want to expand on it here. What's probably happening is it's seeing using as a statement and not a keyword. It appears you have something like the following:
using System;
namespace TestNamespace
{
using Foo.Common;
public Class { }
}
Try
using System;
using Foo.Common;
namespace TestNamespace
{
public Class { }
}
Instead.
It looks like Foo Bar got this error because his project's target framework was set to the client profile.
Just thought I'd add one more 'solution' -- I created a library that targeted the 4.5 framework. My older project was tarting the 4 framework. I got this error.
Changing the older project to 4.5 made it work.