|
System.DirectoryServices.dll file has been added successfully to Visual C++ project through References in Solution Explorer
using namespace System.DirectoryServices;
void CClassName::MethodName(){
...
DirectorySearcher* directorySearcher = new DirectorySearcher();
directorySearcher->ClientTimeout = 60000;
...
}
file.cpp(1268): error C2059: syntax error : '.'
file.cpp(1701): error C2061: syntax error : identifier 'DirectorySearcher'
file.cpp(1701): error C2065: 'directorySearcher' : undeclared identifier
file.cpp(1701): error C2065: 'DirectorySearcher' : undeclared identifier
file.cpp(1268): error C2143: syntax error : missing ';' before '.'
file.cpp(1702): error C2228: left of '->Timeout' must have class/struct/union type
type is ''unknown-type''
file.cpp(1268): error C2871: 'System' : a namespace with this name does not exist
file.cpp(1702): error C3861: 'directorySearcher': identifier not found, even with argument-dependent lookup
By this way I need to set Request Timeout for SOAP WebService
modified 1-Apr-22 10:37am.
|
|
|
|
|
The first error message is telling you that there is something wrong with that using statement, as it does not recognise the use of the period character. The cause is likely to be in the preceding lines which you have not shown. Alternatively you have placed the directive in the wrong part of your source; see using directive - C# Reference | Microsoft Docs[^].
|
|
|
|
|
I have another using namespace just before and it is OK:
using namespace YarpaB2BService;
using namespace System.DirectoryServices;
I am working with Visual C++ .NET
|
|
|
|
|
I cannot find a definitive statement on this, but try the following:
using namespace System::DirectoryServices;
|
|
|
|
|
Sorry,
I have tried it. It's the same errors besides: file.cpp(1268):syntax error : '.'
And one new file.cpp(1268): 'DirectoryServices' : a namespace with this name does not exist
|
|
|
|
|
It cannot be the same syntax error. The message you show complains that you are still using the period instead of the double colon.
|
|
|
|
|
I am using double colon.
The error message "file.cpp(1268):syntax error : '.'" has disapiered
|
|
|
|
|
I'm running an ASP.NET Core 6 application on an IIS as a Rest Api calling Powershell scripts for specific tasks. It works well from my laptop (Windows 10) but doesn't work when I'm running it on a Windows Server 2019 Version 1809 Build 17763.1935. The error tells me that it cannnot find the assembly "Microsoft.Management.Infrastructure".
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Das System kann die angegebene Datei nicht finden.
File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
"Das System kann die angegebene Datei nicht finden." = "File not found."
Did anyone encounter that problem too? The server has the following things installed:
Microsoft .NET 6.0.3 - Windows Server Hosting
Microsoft .NET Runtime - 6.0.3 (x64)
Microsoft .NET Runtime - 6.0.3 (x86)
Microsoft .NET SDK 6.0.201 (x64)
Microsoft ASP.NET Core 6.0.3 - Shared Framework (x64)
Microsoft ASP.NET Core 6.0.3 - Shared Framework (x86)
Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.28.29913
Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.28.29913
IIS 10.0
Windows PowerShell 5.1
PowerShell 7.2.1
Now to test if it is the server setup missing something I wrote a little .net console application with this code
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
var initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;
using (PowerShell powerShell = PowerShell.Create(initialSessionState))
{
powerShell.AddCommand("whoami");
foreach (var item in powerShell.Invoke())
{
Console.WriteLine(item.BaseObject.ToString());
}
if (powerShell.HadErrors)
{
throw new Exception("powershell script had errors");
}
}
I can run this program on the server without problems. But if I copy-paste this exact code into my Api code it fails with the above error. Any ideas?
|
|
|
|
|
Chances are the account your ASP.NET site is running under does not have permissions to run Powershell. Try creating a normal user account and running your site under that account to test.
No, that is not a viable solution if it does work. The entire point of having such a restricted account is to prevent security issues if someone gets your code to execute something malicious.
|
|
|
|
|
I am new to C# and .net core , I am building billing program to read data from PBX which send on defined TCP port.
It does work , I receive the data but randomly tcp port stop listening and when I check window resource monitor I can see under Network --> Listening Ports --> it doesn't show .
But window service is running, then after restart window service i can see port start listening again.
There is no conflict of ports that I am sure of.
My code logic is as below :
using CDR.Models;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace CDR.Helpers
{
public class CDRServer
{
public static void Listen()
{
Logger.Log("Starting 3cX Listener");
TcpListener server = null;
try
{
Int32 port = 5015;
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
server = new TcpListener(ipAddress, port);
server.Start();
Byte[] bytes = new Byte[1024];
String data = null;
while (true)
{
Console.WriteLine($"Waiting for a connection... on {ipAddress.ToString()} and {port.ToString()}");
Logger.Log($"Waiting for a connection... on {ipAddress.ToString()} and {port.ToString()}");
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");
Logger.Log("Connected!");
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
Console.WriteLine("Received: {0}", data);
Logger.Log($"Received: {data}");
try
{
CDRModel cdr = new CDRModel();
var datasplit = data.Split(',');
cdr.historyidofthecall = datasplit[0];
cdr.callid = datasplit[1];
cdr.duration = datasplit[2];
Logger.Log($"Before Date: {DateTime.Parse(datasplit[3]).ToString()}");
cdr.timestart = DateTime.Parse(datasplit[3]);
Logger.Log($"After Date: {cdr.timestart.ToString()}");
if (!string.IsNullOrEmpty(datasplit[4]))
{
cdr.timeanswered = DateTime.Parse(datasplit[4]);
}
cdr.timeend = DateTime.Parse(datasplit[5]);
cdr.reason_termination = datasplit[6];
cdr.from_no = datasplit[7];
cdr.to_no = datasplit[8];
cdr.from_dn = datasplit[9];
cdr.to_dn = datasplit[10];
cdr.dial_no = datasplit[11];
cdr.reason_changed = datasplit[12];
cdr.final_number = datasplit[13];
cdr.final_dn = datasplit[14];
cdr.from_type = datasplit[15];
cdr.missed_queue_calls = datasplit[16];
cdr.chain = datasplit[17];
Logger.Log(JsonConvert.SerializeObject(cdr));
if (!File.Exists("Db.txt"))
Console.WriteLine("Db.txt file not found");
var url = File.ReadAllText(@"Db.txt");
Logger.Log(url);
RestClient client2 = new RestClient(url);
RestRequest request = new RestRequest(Method.POST);
request.AddParameter("application/json", JsonConvert.SerializeObject(cdr), ParameterType.RequestBody);
var response = client2.Execute(request);
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
client.Close();
Logger.Log("Client Closed");
}
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
Logger.Log(e);
}
finally
{
server.Stop();
Logger.Log("Server Stopped");
}
Console.WriteLine("\nHit enter to continue...");
Console.Read();
}
}
}
|
|
|
|
|
You may well have an unhandled exception killing your application. For instance, you use DateTime.Parse, but what happens if you don't receive a valid date? Use TryParse instead.
|
|
|
|
|
Hello I have the following problem:
We have embedded different visuals from a PBIX file onto a asp.net core razor view.
We have achieved that when a user clicks on a row in a table visual, detect the item and corssfilter the other embedded visuals as the user clicks.
On the Power BI environment you can do the same, but by pressing the CTRL key, you can select multiple rows and then it will filter the whole visuals on that page.
As we achieved the crossfiltering selecting just one we thought it would do the same by pressing CTRL, the problem is that PowerBI Embedded visual is not detecting the CTRL key and it is not actually detecting that we are selecting more than one row and it changes the whole filters to the first selected row.
|
|
|
|
|
I`m going to ask a question the answer to which everybody knows for at least a decade but how does the net framework works? I know that it works like most libraries. You attach the library headers to your project and when the program is run on the target computer it will expect to find the binaries (dll etc.) of the library, the headers of which were previously added to the program. But how is the Net library different from a library granting access to containers, math functions or graphical capabilities. In other words what capabilities does the Net library is adding to your program? Thanks for feedback.
|
|
|
|
|
ok, I`ll start from the other end. What is the difference between a MFC App and a WinForms App? What you`re presented on screen by windows is achieved through binary code, a unique windows frame and windows controls displaying format. So it`s really only about the convenience in coding (which programming language you find easier), after compilation the programs will fit to the same rules regardless if their binary was created from C# (WinForms) code or C++ code (MFC).
If I think about it a windows app bust me like a script even if it`s in a binary form. Several scripts can reside along side each other, this is what it must have been like since windows 95.
The obvious flow in a program would be to call and update the hierarchy/chain of windows from within the main function but that`s not what is taking place in practice, the hierarchy is hidden away, all you can have is feedback when the user is interacting with a control.
modified 18-Feb-22 1:30am.
|
|
|
|
|
That is either too simplistic or too broad or something else.
A library, any library, in any language, provides functionality defined by the library.
A library that provides a method that does math might provide a method that does a maximum of two numbers. It would do that because that is a mathematical operations.
A library that provides a method that returns the size of a file on the file system does that because the library does file system operations. And the size of a file is something that people like to know when the do stuff with the file system.
If you want to know how the maximum function is written then you
1. Learn math
2. Learn the programming language.
3. Code the function
If you want to know how to get the file size then
1. You learn exactly what that means (learn more about file systems.)
2. You will need to research core abilities in other libraries associated with the target file system.
3. Learn the programming language
4. Code the function.
Now you might want to know more about 3 in the prior case. You need to learn about the Microsoft (not .Net) Windows API. And then learn how C# interacts with libraries that are not other C# libraries.
If you want more information than that then it will require books (plural) to fully describe it.
|
|
|
|
|
In essence they are all the same, and the difference is in what the developer actually sees. In C/C++ you make direct calls to the functions in the Win32 libraries. In MFC most of those calls are wrapped in a class that is instantiated, and then called through the objects methods. In C#/VB.NET the Win32 calls are wrapped in the .NET framework classes. In Python they are wrapped in Python libraries. And all the libraries make this work by using the system calls provided by the operating system. The real issue is how these frameworks make the developer's job easier, by hiding the (often complicated) system interface.
|
|
|
|
|
Thanks Richard
Quote: In MFC most of those calls are wrapped in a class that is instantiated
Someone like me find this statement to be revealing
|
|
|
|
|
Hello and thank you for any help you may provide. I have a problem that is in my head for the past week and that I can't resolve and I will appreciate any help in resolving it.
In my head I would like to classify objects by category and sub-category, and have the sub-category have object properties according to the subtype... for example
OBJECT : Motorcycle => have name like "Harley Davidson 500 Street", etc
> Category : Automotive > Subcategory : Motorcycle > THEN subcategory has a set of sub-properties like: Engine, Brand, Color, Price,
OBJECT Handbag => have name like "Gucci Guapisima Wherever Edition", etc
> Category : Clothing and Apparel > Subcategory : Brand Handbags > THEN subcategory has a set of sub-properties like: Material, Size, Color, Price,
Not the way I see it is... Most of object share the majority of this structure, like all objects have name, all of them belong to a category and a sub-category, now the problem comes on how to setup properties for each sub-category... for example both objects share the Color and Price but not the other properties. How to make this non-hard-coded? in other words, we know some of the properties are shared between objects, how can we do a model like this and then put this into a form?
I could do a dictionary but in the end, how do I validate them in the form?
Thanks for any help you could provide me.
|
|
|
|
|
You are referring to Classes. In example 1 your base class is Automotive , and the derived class is MotorCycle . You could also have another derived class named Car , etc. See Classes | Microsoft Docs[^] for full details.
|
|
|
|
|
Guillermo Perez wrote: How to make this non-hard-coded?
If you mean that the complete list of properties aren't / can't be known "up front" when you're compiling your code, then you'll need something like an Entity–attribute–value model[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you mr Richard, this is more a realistic approach to what I'm looking for, thank you again!
|
|
|
|
|
using System.Diagnostics;
namespace cpu_performance
{
internal class Class1
{
static void Main(string[] args)
{
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter
{
CategoryName = "Processor",
CounterName = "% Processor Time",
InstanceName = "_Total"
};
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + "%");
Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB");
Console.WriteLine();
while (true)
{
System.Threading.Thread.Sleep(1000);
DateTime localDate = DateTime.Now;
Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + " %");
Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB");
Console.WriteLine("Local date and time: {0}, {1:G}", localDate.ToString(), localDate.Kind);
Console.WriteLine();
if ((int)cpuCounter.NextValue() > 80)
{
System.Threading.Thread.Sleep(100 * 60);
}
}
}
}
}
|
|
|
|
|
Few questions for you to think about
- Which database - relational, graph, document?
- What is the database design like - tables, columns, FKs etc.
Then, find a suitable library which allows you to connect to the database and writes to it. For example if you choose SQL or any other relational database, you could make use of ADO.Net and write the database through dataset or direct queries.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
1. Learn the basics of how databases work. Both design and actually using one.
2. Choose a database to use
3. Learn how C# interfaces with databases in general and specifically how the database in 2 works with C#.
4. Design a table that will hold the data. This follows from 1.
5. Put all of the above together.
|
|
|
|
|
I know this may seem arbitrary to some, but the nature of the project that I am currently working on makes this capability an easy way to solve several problems.
I want an efficient, seamless way to integrate values into a stream of characters. I have done this in the past by just converting byte values into chars or even using value.tostring() but it would be more efficient if the characters could be read directly from the memory containing the values. (Examples: an integer is read as 2 characters, a long is read as 4 characters and a GUID is read as 8 characters). This would be really simple in C++. In c# it is turning out to be a huge challenge.
I tried using a generic with using StructLayout.Explicit but I got a runtime error stating that this is not supported. Using non-generics doesn't work either because strings and arrays are classes while values are structs and mixing them also doesn't work for the simple reason that the non zero terminated strings used in .NET track data that is probably inconsistent with this layout.
Is there any way to directly read (or even copy) data from numeric value bytes into a string? I can think of one possibility using unsafe copying but was wondering if I had any other better (more efficient) options.
|
|
|
|