Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

reuse process object

$
0
0

Hi,

is it legitimate to reuse the process object? I have some code that stops after running 646 times, and haven't yet found out why. The code looks like this:

            System.Diagnostics.Process pr = new System.Diagnostics.Process();
            pr.StartInfo.UseShellExecute = false;
            pr.StartInfo.RedirectStandardOutput = true;
//numRuns is currently set to 1000.
            for (i = 0; i <= numRuns; i++)
            {
                number = String.Format("{0,4:D4}", i);
                Console.WriteLine(number);
                if (i==0)
                {
                    pr.StartInfo.FileName = "copasise.exe";
                    pr.StartInfo.Arguments = "TFD.cps";
                    pr.Start();
                    pr.WaitForExit();
                    pr.Refresh();
                }
                else
                {
                    pr.StartInfo.FileName = "copasise.exe";
                    pr.StartInfo.Arguments = "TFS.cps";
                    pr.Start();
                    pr.WaitForExit();
                    pr.Refresh();
                }
//The rest of the loop modifies the file produces by the process.


Tom


System.Security.Cryptography.CryptographicException: Access denied when trying to call System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent

$
0
0
I am writing a simple example code to demonstrate how encryption and decryption with the X509 certificates works.

		public static byte[] Encrypt(byte[] content, X509Certificate2Collection encryptingCertificates)
		{
			if (content == null)
			{
				throw new ApplicationException("NullContent");
			}
			if (encryptingCertificates == null || encryptingCertificates.Count == 0)
			{
				throw new ApplicationException("NoCertificates");
			}

			CmsRecipientCollection recipients = new CmsRecipientCollection(SubjectIdentifierType.IssuerAndSerialNumber, encryptingCertificates);
			EnvelopedCms dataEnvelope = new EnvelopedCms(new ContentInfo(new Oid("1.2.840.113549.1.7.1"), content), new AlgorithmIdentifier(new Oid("2.16.840.1.101.3.4.1.2")));
			dataEnvelope.Encrypt(recipients);

			return dataEnvelope.Encode();
		}

		public static byte[] Decrypt(byte[] encryptedContent, X509Certificate2Collection decryptingCertificates)
		{
			if (decryptingCertificates == null || decryptingCertificates.Count == 0)
			{
				throw new ApplicationException("NoCertificates");
			}

			EnvelopedCms dataEnvelope = new EnvelopedCms();

			dataEnvelope.Decode(encryptedContent);
			dataEnvelope.Decrypt(decryptingCertificates);

			ContentInfo contentInfo = dataEnvelope.ContentInfo;

			return contentInfo.Content;
		}



And i have encountered with a problem - the code which have to decrypt (dataEnvelope.Decrypt(decryptingCertificates)) throw CryptographicException: Access denied.

    CryptographicException: Access denied.
       at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
       at CertificateTestingTool.CertificateResolver.Decrypt(Byte[] encryptedContent, X509Certificate2Collection decryptingCerti
    ficates)
       at CertificateTestingTool.Program.Main(String[] args)

It happens on the windows server 2012 and windows 8.
I have checked this code on the win server 2008 and win 7 it works fine.

Additional information: I don’t use PKI, I import *.pfx file with the private key from a folder (X509Certificate2Collection.Import(…)) and it have imported successfully.

		public static X509Certificate2Collection GetCertificates(string certPath, string password)
		{
			X509Certificate2Collection certs = null;
			var logger = Log.Logger;
			certs = new X509Certificate2Collection();
			certs.Clear();
			var flags = X509KeyStorageFlags.DefaultKeySet;
			certs.Import(certPath, password, flags);

			return certs;
		}


Could anybody help me with this? As I understand some permission rules were introduced at the new OS version.



POS for .NET service as a pass through

$
0
0

Hello,

Has anyone come across the issue that an app using OPOS/Pos for .Net has been sending data that are not OPOS standard related rather look like ESC Pos or ESC commands of a specific printer?

I have the problem that a customer was using an app that did this and my SO was sending the data via PrintNormal to the printer but due to the fact that the data were HEX representations of ESC commands some parts got filtered out by the SO and others just send through like text.

Hope anyone can help.

Thank you,

\Manfred

Net framework versions supported by windows

$
0
0

hello
a query, any net framework could be installed on any Windows desktop or server, and as I have understood that if I have a windows application in net 4.5.1, could run on windows xp to windows 8.1
same for the web: aspnet ...

Refrence Error From Windows Service

$
0
0

I am facing one issue when referencing one namespace.

I have create two Different Project in one solution

  1. Class Library Project.
  2. Windows Service Project

Class Library Project namespace is PRC.B2B.Common and Windows Service Project namespace isPRC.B2B.SchedulerService

I am facing issue about referencing class library project in Windows Service Project.

I want to refer PRC.B2B.Common in PRC.B2B.SchedulerService but after adding reference and trying to access the namespace there is no error but when i try to build the project i am getting below error :-

Issue Says

The type or namespace name 'Common' does not exist in the namespace PRC.B2B.Common (are you missing an assembly reference?

I am not certain with windows application, what could be the issue ?

Weird WMI RPC Server is unavailable (Exception from HRESULT: 0x800706BA)

$
0
0

Dear All,

I found weird error due  to WMI RP Server unavailable. The situation is I'd like to compare the CPU usage between 2 or more servers. I will open the RDC file for the lowest CPU usage. The problem is, when I called the first server CPU usage, it worked fine, but when I called the second server CPU usage, the error came.

I have switched the second called server error to the first one (I'm using properties to list all servers that I'd like to check), and the result was the same, the second called server was error.

I've debugged and realized that I need to close the scope/searcher session. Do you know how to close those session ?

I've used dispose method but the result was the same.

This is my code to get the available usage.

foreach (string servers in ArrServerCollection)
            {
                AvailableUsage[i] = this.GetAvailableUsage(servers);

                if (i > 0)
                {
                    if (AvailableUsage[i] < AvailableUsage[i - 1])
                        getIndexUsage = i;
                }

                i++;
            }

and this is my getAvailableUsage() method

                    

private Int64 GetAvailableUsage(string computerName)
        {
            Int64 PercentProcessor = 0;
            ManagementObjectCollection services;
            ManagementObject queryObj;

            services = null;
            queryObj = null;

            ManagementScope scope = CreateNewManagementScope(computerName);

            SelectQuery query = new SelectQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor");

            try
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
                {
                    services = searcher.Get();
                    queryObj = services.Cast<ManagementObject>().First();

                    PercentProcessor = Convert.ToInt64(queryObj["PercentProcessorTime"]);

                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            return PercentProcessor;
        }

I've added refresh variable to clear the memory, but the error is still coming.

Please advise.

Best REgards,

Afin


Best Regards, Afin


ie 11 hangs when trying to access the .config file for a iehost component

$
0
0

Using IE10 on windows 8 i am able to turn on IEHosting of a .NET component.  IE11 on win 8.1 doesn't seem to work correctly.

for ie10 i make this registry change to enable ieHosting documented here http://msdn.microsoft.com/en-us/library/hh367887.aspx#web

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework EnableIEHosting=1 

when using ie11 the page hangs while loading my component

mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext) + 0x18 bytes    
     System.Configuration.dll!System.Configuration.ClientConfigurationSystem.EnsureInit(string configKey) + 0x68 bytes    
     System.Configuration.dll!System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(string sectionName) + 0x14 bytes    
     System.Configuration.dll!System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(string sectionName = "appSettings") + 0x14 bytes    
     System.Configuration.dll!System.Configuration.ConfigurationManager.GetSection(string sectionName) + 0x38 bytes    
     System.Configuration.dll!System.Configuration.ConfigurationManager.AppSettings.get() + 0xf bytes    
     System.dll!System.Diagnostics.PerformanceCounterLib.GetLocalizedPerfCounterMode() + 0x33 bytes    
     System.dll!System.Diagnostics.PerformanceCounterLib.IsLocalizedMode() + 0x12 bytes    
     System.dll!System.Diagnostics.PerformanceCounterLib.IsCustomCategory(string machine = ".", string category = ".NET CLR Networking") + 0x21 bytes    
     System.dll!System.Diagnostics.PerformanceCounter.Initialize() + 0x4bd bytes    
     System.dll!System.Diagnostics.PerformanceCounter.RawValue.set(long value = 0) + 0x1a bytes    
     System.dll!System.Net.NetworkingPerfCounters.Initialize() + 0xfd bytes    
     System.dll!System.Net.Configuration.SettingsSectionInternal.SettingsSectionInternal(System.Net.Configuration.SettingsSection section) + 0x220 bytes    
     System.dll!System.Net.Configuration.SettingsSectionInternal.Section.get() + 0x86 bytes    
     System.dll!System.Net.Configuration.SettingsSection.EnsureConfigLoaded() + 0x26 bytes    
     System.dll!System.Configuration.Internal.ConfigurationManagerHelper.System.Configuration.Internal.IConfigurationManagerHelper.EnsureNetConfigLoaded() + 0x6 bytes    
     System.Configuration.dll!System.Configuration.ClientConfigurationSystem.EnsureInit(string configKey) + 0xd6 bytes    
     System.Configuration.dll!System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(string sectionName) + 0x14 bytes    
     System.Configuration.dll!System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(string sectionName = "system.diagnostics") + 0x14 bytes    
     System.Configuration.dll!System.Configuration.ConfigurationManager.GetSection(string sectionName) + 0x38 bytes    
     System.dll!System.Configuration.PrivilegedConfigurationManager.GetSection(string sectionName) + 0x21 bytes    
     System.dll!System.Diagnostics.DiagnosticsConfiguration.GetConfigSection() + 0xd bytes    
     System.dll!System.Diagnostics.DiagnosticsConfiguration.Initialize() + 0x69 bytes    
     System.dll!System.Diagnostics.DiagnosticsConfiguration.Sources.get() + 0xa bytes    
     System.dll!System.Diagnostics.TraceSource.Initialize() + 0x58 bytes    
     System.dll!System.Net.Logging.InitializeLogging() + 0xe8 bytes    
     System.dll!System.Net.Logging.On.get() + 0xf bytes    
     System.dll!System.Net.WebRequest.Create(System.Uri requestUri = {System.Uri}, bool useUriBase = false) + 0x14 bytes    
     System.dll!System.Net.WebRequest.Create(System.Uri requestUri) + 0x1d bytes    
>    xFmrClnt.DLL!xFmrClnt.Post.TestUserAuthentication(System.Uri destWebUriServer = {System.Uri}) Line 76 + 0x9 bytes    C#

any help or insight would be great!

thanks




Microsoft.Bcl.Async in Silverlight 4 - CancellationTokenSource/CancellationToken are not CLS Compliant

$
0
0

Hi,

I'm using the latest version of the Microsoft Async (Microsoft.Bcl.Async) NuGet package in a Silverlight 4 application and I'm receiving this specific "Warning As Error".

Warning as Error: Argument type 'System.Threading.CancellationToken' is not CLS-compliant


I know I can suppress it via this attribute

[ClsCompliant(false)]

but that would require me to put this all throughout my application, which is not feasible.

Has anyone else run into this issue with this library? Is this a known issue? The rest (including async await, work perfectly.

Cheers,

Alastair


Serial Port Issues

$
0
0

Hi

I am working on embedded ssytem. I have to read a data from rs232 port using 9600 baud rate from an external device. reception and transmission is normally going fine, but if my external device start sending data to my sytem before i initialize my system, no data is recieved. i have tried using implementing time out technique but didnt work. i have also checked all this scenario on hyper terminal of my system, but same response as above. can you tell me about this problem. i am using visual c++ programming and my system is equip with xp embedded.

Printing a document in C# best approach

$
0
0

am searching for a namespace in C# through which i can "print and monitor printing".Currently i used 'process' to print a pdf ; But here i cannot monitor printing.Since process just throws document to printer.I went through Win32_Printer and System.printing both of them are dealing with "controlling/monitoring print jobs" but not printing a document.

How i print now:

ProcessStartInfo psInfo =newProcessStartInfo();
psInfo.Arguments=ConfigurationManager.AppSettings["printer_name"];
psInfo.FileName= fileName;
psInfo.WindowStyle=ProcessWindowStyle.Hidden;
psInfo.Verb="print";
psInfo.CreateNoWindow=false;
psInfo.UseShellExecute=true;
process =Process.Start(psInfo);

what WMI does: http://www.codeproject.com/Articles/6592/A-simple-approach-for-controlling-print-jobs-using and http://msdn.microsoft.com/en-us/library/aa394370.aspx

All i need to do is check print status of a document i have printed at the moment.Printed or not!!

OracleDataReader returns more rows than the same query in SQL Plus

$
0
0

We've run into a weird problem where a query executed using OracleCommand returns more (duplicate) rows than the exact same query executed in SQL Plus.

More specifically the query in SQL Plus returns 9 rows while the query using OracleCommand.ExecuteReader() returns 12 rows. The additional rows are duplicates of 3 of the 9 previous rows. The result set is the same each time.

It's a simple select on one table with filtering on three of the columns. This problem has occured with two of our customers and we've not been able to replicate them in our testing environment.

Anyone experienced this problem?

Kind regards,

Christoffer


Disabling HttpWebRequest autoredirection

$
0
0

Hi,

I have an application which sends HttpWebRequest to the server and handles the responses. I have to use AllowAutoRedirect property to false in order for disabling auto redirect.

Can we achive the same functionaliy without making any code change by doing any setting in registry or IE.

Thanks


Navyatha

Scada and HMI

$
0
0
Hi all,
Is there classes in the .Net framework for Scada and HMI development for industry and automation .

Regards...

can i format & color excel cells in .net by OleDb connection and without MS Office installation

$
0
0

can i format & color excel cells in .net by OleDb connection and without MS Office installation

How to close Windows form through User control

$
0
0
Dear All,

I have a User control with a button = CLOSE

i want to use that control on windows form.

Now when i run that windows form, and click on CLOSE button, it should close form, but it won't do it, Even though I am passing the form object as reference to method in User control class.

any idea or advice or sample code.

Many Thanks,
Fahim

XmlSerialization is not working ??

$
0
0

This is my serialized XML

<?xml version="1.0" encoding="utf-8"?>
<HTraceConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <HTraces>
    <HTrace>
      <HHandlers>
        <HHandler>
          <HFileName>
            <Name>FileName string</Name>
          </HFileName>
        </HHandler>
        <HHandler>
          <HFileName>
            <Name>FileName string</Name>
          </HFileName>
        </HHandler>
      </HHandlers>
    </HTrace>
    <HTrace>
      <HHandlers>
        <HHandler>
          <HFileName>
            <Name>FileName string</Name>
          </HFileName>
        </HHandler>
        <HHandler>
          <HFileName>
            <Name>FileName string</Name>
          </HFileName>
        </HHandler>
      </HHandlers>
    </HTrace>
  </HTraces>
</HTraceConfig>


This is my class file

 [Serializable]
    public class HTraceConfig
    {
        private List<HTrace> hTraces;

        public List<HTrace> HTraces
        {
            get { return this.hTraces; }
            set { this.hTraces = value; }
        }

        public HTraceConfig() { }

        public HTraceConfig(List<HTrace> HTraces)
        {
            this.HTraces = HTraces;
        }
    }

    [Serializable]
    public class HTrace
    {
        private List<HHandler> hHandlers;

        public List<HHandler> HHandlers
        {
            get { return this.hHandlers; }
            set { this.hHandlers = value; }
        }

        public HTrace() { }

        public HTrace(List<HHandler> hHandlers)
        {
            this.HHandlers = hHandlers;
        }
    }

    [Serializable]
    public class HHandler
    {
        private HFileName hFileName;

        public HFileName HFileName
        {
            get { return this.hFileName; }
            set { this.hFileName = value; }
        }

        public HHandler() { }

        public HHandler(HFileName fileName)
        {
            this.HFileName = fileName;
        }
    }

    [Serializable]
    public class HFileName
    {
        private string name;

        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public HFileName() { }

        public HFileName(string Name)
        {
            this.Name = Name;
        }
    }


while serializing it is working fine. but when deserialzing if i keep break point in any of the properties set, I am getting list count as zero because I need to call some method to initialize other values while setting that property value. Please any one help me...


WshRuntimeLibrary TargetPath problem with Cyrillic chars

$
0
0

Hi,

I tried to create a shortcut with Cyrillic chars in path. I got

System.ArgumentException : Value does not fall within the expected range.

at IWshRuntimeLibrary.IWshShortcut.set_TargetPath(Stringout_Path)

The code is pretty straightforward :

using IWshRuntimeLibrary;

 public static void CreateFileLink( String sourceFilePath, String linkDestinationFolderPath )
        {
            var wsh = new IWshShell_Class();
            FileInfo fileInfo = new FileInfo( sourceFilePath );
            var shortcut = wsh.CreateShortcut( String.Format("{0}\\{1}.lnk",linkDestinationFolderPath,fileInfo.Name) ) as IWshShortcut;
            if( shortcut != null )
            {
                shortcut.TargetPath = sourceFilePath;
                shortcut.WindowStyle = 1;
                shortcut.Save();
            }
            else
            {
                log.WarnFormat(
                    "ShortCut couldn't be created for {0} at {1}", sourceFilePath, linkDestinationFolderPath );
            }
        }

[Test]

        public void TestShortCutWithCyrillicCreation()
        {
            CreateFileLink(Environment.CurrentDirectory + "\\28.06.чай\\_malina4.jpg", Environment.CurrentDirectory);

            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + "\\_malina4.jpg.lnk"));
        }

 Did anybody encounter similar issue? Thanks!


Max

Problem with System.IO.Ports.SerialPort

$
0
0

I'm trying to deploy an application using SerialTool, and I keep getting the error :

"The given port name does not start with COM/com or does not resolve to a valid serial port".

 

I'm using VS 2005 and Framework 2.
I have had no issues what so ever on my development machine, which is using a USB serial port only.

I've tried a standard port on COM1 and a USB serial port on COM3.

In all cases, I can make the printer work using "ECHO TEST > COM1" from the DOS command line.

 

Here is a simple test program which (most of the time) fails to work on either COM1 or COM3

 

using (System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort(comboBox1.Text))

try

{

port.Handshake = System.IO.Ports.

Handshake.None;//.RequestToSend;

port.BaudRate = 9600;

port.Parity = System.IO.Ports.

Parity.None;

port.DataBits = 8;

port.StopBits = System.IO.Ports.

StopBits.One;

port.Open();

AddMessage(

"Opened");

port.DiscardInBuffer();

port.DiscardOutBuffer();

port.Write(

"THIS IS A TEST\r\n");

if (cbHoldOpen.Checked)

MessageBox.Show("press OK to close");

port.Close();

AddMessage(

"Done");

}

catch (Exception ex)

{

AddMessage(ex.Message);

}

 

Any help would be greatly appreciated !

 

chris

POS For .NET FiscalPrinter class: amount of cash

$
0
0
I'm writing POS For .NET driver for Fiscal Printer device.

Fiscal Printer device holds the amount of cash in fiscal memory. This amount is changed by printing cash-in or cash-out receipt or printing sale or refund receipt (if cash payment is used, not card payments). My POS For .NET driver can read this amount from the device, but I don't know how to pass this amount to Application

So the question is: what is the correct way to pass amount of cash from the FiscalPrinter driver class to the Application?

The compiler and comparator as a component of the system for educating students

$
0
0

Applicationwas made​​as aa final workat the Facultyof InformationTechnology -Mostarby studentsSanin Palikuća andArifDžambo.The applicationwill beused by the studentsof thecollegewhere they willreducethe possibilityof rewritingas well and automaticallychecksthe correctnessas well asdetermining thesimilarities betweenthe works.Your commentsarewelcome. Thank you,Sanin.

On the following linkyou canseeapplication:
http://www.youtube.com/watch?v=UZd152Otpnw

Viewing all 8156 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>