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

cannot implicitly convert type string to double

$
0
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Currency
{
    class Program
    {
        static void Main(string[] args)
        {
            // Declare Source and Target Currency.
            string SCurrency, TCurrency;

            //Declare and intialising a String currency array and a Double rate array.
            String[] currency = new String[] {"Euro","Rupees","Dirhams"};
            double[] rateAR =new double[] {0.73,62.68,3.67};
            double TAmount,SAmount,Rate;

            //Printing the TITLE and setting font color.
            Console.Title = "Currency Application";
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("********CURRENCY CONVERTOR*********");

            //Getting the Source and Target Currency.
            Console.WriteLine("Enter the source currency in Dollars: ");
            SCurrency = System.Console.ReadLine();
            Console.WriteLine("Enter the target currency : ");
            TCurrency = System.Console.ReadLine();
            Console.WriteLine("Enter the amount to convert : ");
            SAmount = System.Console.ReadLine(); ------------ > ERROR
            for(int i=0;i<3;i++)
            {
                if (TCurrency == currency[i])
                {
                    rateAR[i]=Rate;
                }
            }

            TAmount = SAmount * Rate;
            String StringAmount = Convert.ToString(TAmount);
            System.Console.WriteLine("Converted Amount : " + StringAmount + ".");

            Console.BackgroundColor = ConsoleColor.Black;


            Console.ReadLine();

how to use reflection to find the data type of a class property

$
0
0

I have a C# class called "equipment" with several defined properties with different data types; such as int, bool, string.  I use Reflection to with a variable name to find the property and set its value from a control's value, but before doing so, I would like to know the property's data type.  How can I do that?

The following is an example of how I set the value:

equipment equip = new equipment();
PropertyInfo piInstance;

for (int i = 0; i < pnlEquipmentDetails.Controls.Count; i++) { . . . TextBox tbm = (TextBox)pnlEquipmentDetails.Controls[i]; piInstance = typeof(equipment).GetProperty("equipmentName")); piInstance.SetValue(equip, tbm.Text, null); . . . }


This works well if the type is string, but it the property is of type int, I need to parse tbm.Text.  How can I determine the property's type with Reflection?


Rob E.


Using SerialPort class to communicate with USB CDC device

$
0
0
I'm using the SerialPort class to communicate with a USB CDC class device. I'm using the Write method to send a message and ReadByte to read the response one byte at the time (response is usually 2 bytes). The problem I'm having is that sometimes the ReadByte method timesout even though the response was sent by the device and received by the USB stack (I can see it in USB analyzer). Any suggestions?

what is the best and optimised way to load controls dynamically in winforms C#?

$
0
0

I am building a winform Application. I have to create buttons dynamically based on data fetched from database. I followed following steps

  1. Created UserControl
  2. On UserControl_Load event I fetched data from database.
  3. I populated the UserControl with buttons based on number of rows i get from the database.

The above approach proved too slow. The form loads slowly. It takes time to populate buttons. So Which is the best and optimised way to load controls dynamically in C# winforms?


markand

How to Convert a WPF Windows Application to dll

$
0
0

Hi All,

How to Convert a WPF Windows Application to dll

Regards,

Nidheesh

misteremanone@hotmail.com

$
0
0
What is .NET Framework and do I need it on my PC?

C++/CLI - How to translate ?

$
0
0

Hey folks. I got a Plugin Host whicht expects a DLL that is TypeOf(iPlugin) Internface. This Host is written under VB.NET Framework 4.5.

However: How do I write a Plugin under C++/CLI that is exporting that iPlugin::TypeId?

I have to following but it will not be recognized by the catlog/container classes as type of iPlugin.

How do I have to export the ID in a correct way? My definition in the header file is:

#pragma once

using namespace System;
using namespace System::ComponentModel::Composition;
using namespace SharedLibrary;
using namespace Plugin_Interface;

namespace MyCppPlugin {
	
	[System::ComponentModel::Composition::ExportAttribute(IPlugin::typeid)]
	public ref class MyPlugin abstract : public Plugin_Interface::IPlugin
	{
	public:
		virtual bool CreateInstance(SharedLibrary::MemoryArbiter^%, SharedLibrary::clsMessageQueue^%, SharedLibrary::clsGPIO^%, SharedLibrary::Types^%, SharedLibrary::DisplayDriver^%);
		virtual bool DeleteInstance(void);
		virtual void ForceUnload(void);
		virtual void Interrupt(void);
		virtual void Main_Loop(void);
	};
};

Thank you :)

fps too slow when using direct draw (WEC7 on i.MX53)

$
0
0

I'm using a freescale i.MX53 with all the freescale codec installed under WEC7.
I need to use an USB camera to viualize a video and to record a video.
I use the USB WebCam driver from codepkex ( http://cewebcam.codeplex.com/ ) compiled under WEC7.
When I try to visualize the video stream using DirectDraw all it's fine, but when I try to stast to record a video, The fps is around 3/5 Fps and the CPU usage rise up at 100%.
I notice that the IOCTL that take the buffer from the USB driver is called every 300 milliseconds.
If I try to call directly the IOCTL, I can read the buffer immediately, so it seems that the problem is between direct draw and the codec.

Any help is appeciated!


Beppe Platania Windows Embedded MVP http://blog.bepseng.it



Windows service getting stopped abruptly

$
0
0

Hi,

I have a windows service application which pings server continuously every 10 secs and downloads files from the server.

Recently, I have faced an issue where suddenly service is getting stopped and I cannot see anything in my log. My code has proper exception management and there is very less chance a error is not caught.  

Is there any other way to find out whats wrong and the rootcause for this behaviour.

I have figured out that this is the exception that I'm getting in Event viewer.

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.WebException
Stack:
   at System.Net.ServicePointManager.FindServicePoint(System.Uri, System.Net.IWebProxy, System.Net.ProxyChain ByRef, System.Net.HttpAbortDelegate ByRef, Int32 ByRef)
   at System.Net.HttpWebRequest.FindServicePoint(Boolean)
   at System.Net.HttpWebRequest.get_ServicePoint()
   at System.Net.AuthenticationState.PrepareState(System.Net.HttpWebRequest)
   at System.Net.AuthenticationState.ClearSession(System.Net.HttpWebRequest)
   at System.Net.HttpWebRequest.ClearAuthenticatedConnectionResources()
   at System.Net.HttpWebRequest.Abort(System.Exception, Int32)
   at System.Net.HttpWebRequest.AbortWrapper(System.Object)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Event Xml:

Thanks in advance.


Navyatha


How garbage collector can identify which objects are unused

$
0
0
How garbage collector can identify which objects are unused , i read in some websites about the garbage collector but its not clear for me.when garbage collector walk through the heap how garbage collector can identify which objects are unused.

RequestValidationMode change from 2.0 to 4.5

$
0
0

My current application is using RequestValidationMode=2.0 for now and planning to move to RequestValidationMode=4.5.

We are currently using .Net Framework 4.5.

There are any specific things to be taken care before targeting to requestvalidationmode to 4.5? Please advice.

Thanks,

Kompella

Duplicate keys in appSettings in App.Config

$
0
0

If I have the following xml in my App.Config

  <appSettings>
    <add key="Key" value="Value1" />
    <add key="Key" value="Value2" />
  </appSettings>

then calling ConfigurationManager.AppSettings.GetValues("Key") returns an array of strings with only one entry -- the last entry in in the appSettings ("Value2").

There was a useful article written on how to get this to work on CodeProject (http://www.codeproject.com/dotnet/namevaluemultiple.asp), but that doesn't seem to work with .net 2.0 (I get a run-time exception that the appsettings section can't be modified).

Does anyone know of a sample somewhere on how to get this to work in .net 2.0?

Check if a dll is registered or not?

$
0
0
Hi all, 

I am trying to verify if a dll is registered or not? 

I am trying to write a function which will check if a dll is registered and return me T/F accordingly !!

Please advise.

Thanks. 

StreamWriter Class Question: How do you know if the writer is open?

$
0
0

In the following c# example, is there a way to determine if the writer is open.  I want to know if the writer is open before I do something with it.

writer = new StreamWriter(File.OpenWrite(@"c:\output.txt"));

 Also when I am done with the writer, should I close() it, dispose() it or both?


-7

Linq confusion - Nube question

$
0
0

Hi

I'm just starting to look at LINQ to XML to access information from a web service. I have the code below:

var z = from c in xdoc.Descendants("content")
where c.Value == "Asbestos" && c.ElementsAfterSelf("item").Count<XElement>() > 0
select new
{
     xnode = c.ElementsAfterSelf("item").Descendants("content").Elements("name")
};

When I run the code, and expand the results views for z, I get the following:

<name class="Document" icon="Images/Icons/Document.png" link="Asbestos">http://site.com?docID=1">Asbestos document A 21/01/2014</name>
<name class="Document" icon="Images/Icons/Document.png" link="Asbestos">http://site.com?docID=2Asbestos">">Asbestos Image 1 21/01/2014</name>
<name class="Document" icon="Images/Icons/Document.png" link="Asbestos">http://site.com?docID=3Asbestos">">Asbestos document B 21/01/2014</name>

This does contain the data I want, but I want to have it as a data table so I can bind it to a gridview or similar as below:

Type                  link                                          filename

Document          http://site.com?docID=1           Asbestos document A 21/01/2014

Document          http://site.com?docID=2Asbestos">           Image 1 21/01/2014

Document          http://site.com?docID=3           Asbestos document B 21/01/2014


Any help appreciated.

Thanks


Open RTF file in MS Word & WordPad

$
0
0
I want to know how can I open an existing license.rtf (located in my application folder) in Microsoft Word and in WordPad?
Jassim Rahma

The request was aborted: Could not create SSL/TLS secure channel..

$
0
0

I am getting this exception intermittently when posting to Twitter. It works sometimes. Other times, specifically when our nightly build runs at 2AM PST, we get this error.

I have turned on network tracing. We are getting a "returned code=IllegalMessage" in the logs. Here is the relevant section from the logs. Note, Twitter does NOT require client certificates, so that is not an issue. When this call succeeds, I get"returned code=OK" and I see the Twitter SSL cert in the logs.

System.Net Information: 0 : [3876] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 5c18473730:760f4e8390, targetName = api.twitter.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [3876] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=IllegalMessage).
System.Net.Sockets Verbose: 0 : [3876] Socket#46140748::Dispose()
System.Net Error: 0 : [3876] Exception in HttpWebRequest#3781642:: - The request was aborted: Could not create SSL/TLS secure channel..
System.Net Verbose: 0 : [3876] HttpWebRequest#3781642::EndGetResponse()
System.Net Error: 0 : [3876] Exception in HttpWebRequest#3781642::EndGetResponse - The request was aborted: Could not create SSL/TLS secure channel..



An online free FTPS server?

$
0
0
Hi, is there a free online FTPS server, which I can try my FTP code?

Updated Dll not being called

$
0
0

Hi,

I have a C# project, it consist of multiple projects which are referencing each other,

I have a file ab.cs which is generating html page dynamically,I changed the look of html page by adding some of my code.

this ab.cs exist in a project PK.dll

another dll HK.dll is calling the function exist in ab.cs

and the main from where I am calling HK.dll directly...

main()--->HK.dll----->function call to function in ab.cs

the project is running fine only the changes I have done in ab.cs are not getting reflected in my HTML page.

I have already removed and added references again from project tab....cleaned the solution and rebuild.....

Please provide some solution if possible...

NamedPipeServerStream calls Async callback when disposed

$
0
0
Hallo!

I've got a strange behaviour of the NamedPipeServerStream class.
It calls async callback function, when disposing.

1. I start async wait for connection

pipeServer =

newNamedPipeServerStream("MyPipe", PipeDirection.InOut,1,PipeTransmissionMode.Byte,PipeOptions.Asynchronous);

pipeServer.BeginWaitForConnection(

newAsyncCallback(PipeWaitConnectionCallback), null);

2. Next, I finish it by disposing the pipe.

pipeServer.Dispose();


3. At this point, somewhere in Dispose method  PipeWaitConnectionCallback is called and I get ObjectDisposedException in a call to pipeServer.EndWaitForConnection


The question is - why callback method is called in Dispose of NamedPipeServerStream? I am really not expect such behaviour.
Viewing all 8156 articles
Browse latest View live


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