BitConverter.ToInt32 - weird optimization?
Now, if we take a look at the reflected BitConverter.ToInt32 method it looks
something like this:
public static unsafe int ToInt32(byte[] value, int startIndex)
{
if (value == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
}
if (((ulong) startIndex) >= value.Length)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex,
ExceptionResource.ArgumentOutOfRange_Index);
}
if (startIndex > (value.Length - 4))
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
}
fixed (byte* numRef1 = &(value[startIndex]))
{
if ((startIndex % 4) == 0)
{
return *(((int*) numRef1));
}
if (BitConverter.IsLittleEndian)
{
return (((numRef1[0] | (numRef1[1] << 8)) | (numRef1[2] <<
0x10)) | (numRef1[3] << 0x18));
}
return ((((numRef1[0] << 0x18) | (numRef1[1] << 0x10)) |
(numRef1[2] << 8)) | numRef1[3]);
}
}
What I don't understand is this:
if ((startIndex % 4) == 0)
{
return *(((int*) numRef1));
}
What prevents me from using this method when the remaining product isn't 0?
We already checked if there is 4 bytes to read so I should be able to.
Cheers
Morten Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 127001
WPF ListBox Selecteditem colors
I'm struggling with knowing how to change the colors used when selecting an
item in a databound ListBox. If I have a listbox which uses a datatemplate
for items, I don't know how to use triggers to change the foreground and
background color in the template (if it was a ListBoxItem, I would say
ListBoxitem.IsSelected, but it is a Person for example) based on the item
being selected.
The problem is that the default selection foreground and background color
don't work with my DataTemplate's Gradient colors...text gets hidden Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126995
TcpListener.Start() segfaults
I have a TcpListener that gets started from a GUI button event
handler:
TcpListener listener;
listener = new TcpListener(IPAddress.Any, 1234);
listener.Start(backLog);
As soon as the third line runs, the app freezes, the CPU goes to 100%
on that CPU (Core Duo) and debugging can't break out of it. I can't
even stop the process with the Task Manager but have to reboot to get
it to stop.
Any ideas what's wrong? This is with Visual Studio 2005. I had .Net
3.0 and the newest Windows SDK installed, but just uninstalled them
and it's still a problem.
T Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126992
Do any microsoft buildtime dependancies C#/C/c++/VB/etc. need to be updated for the 2007 policy on daylight savings time?
Do any microsoft buildtime dependancies C#/C/c++/VB/etc. need to be updated
for the 2007 policy on daylight savings time?
I know the OS needs to be updated but I care now about C libraries, .net
binaries, etc. that microsoft maintains which have coded in them logic
around datetime. e.g. the C# and c++ datetime objects that microsoft
maintains, do these have any logic that needs to be updated reguardless of
the OS being updated? Or is all such functinality 100% derived off the OS so
no library or development or build time tool updates nessicary? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126991
Is there a patch for congress new 2007 daylight savings time change?
Is there a patch for congress new 2007 daylight savings time change?
http://geography.about.com/cs/daylightsavings/a/dst.htm This could have
economic impact like y2k did. Is there a patch for windows
95/98/me/xp/2000/2003/etc. to handle new daylight savings time rules? are
there any patches for .net? win32? etc.? what all else is impacted by this
in microsoft products and apis? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126989
Edit Templates
I have a datagrid with edit/update functionality. In the template
columns, I have put more than one control in the editItem Template
area I have more than one control. A text box , label and a checkbox
with a label. When i click edit on the grid, The two labels and the
checkbox end up in the bottom left of the page grouped on top of
eachother. I have no idea why. The text box appears fine and in the
correct place on the grid. Any thoughts? What am i missing? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126979
WPF/Avalon: Adding Controls During Runtime
I have to present inputs (textbox, combobox, etc) that are not known
during design time. In the past this was pretty simple to do. You just
add a new control to the Controls property of a form. How can I
achieve the same thing with WPF?
Thanks Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126978
Wireless Info
What's the recommended way to obtain wireless information in .NET using C#?
I am looking for SSID, signal strength, security mode, channel, etc.
TIA,
midas Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126977
Windows Service Registration
I created Windows Service in VB 2005.
Using InstallUtil.exe I register it on any machine with Windows XP, Windows
2003 Server without any problem. I even never had to learn that process.
After registration I see a couple of new files in the folder where I have My
Service EXE file (MSFaxListener.exe).
Their names are MSFaxListener.InstallLog and MSFaxListener.InstallState. In
the list of Services I see MSFaxListener service.
I tried to install my service on the machine with Vista Business. DOS window
appears for a portion of second. New files do not appear in MyServices
folder and there is no MSFaxListener service in the list of registered
services.
I checked permissions on MyServices Folder. Everything looks OK.
What am I missing? How do I register Windows Service on Vista machine?
Vovan Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126975
Visual Inheritance
(This is being reposted from the CompactFramework group because I
don't belive the situation is specific to CF).
I am creating a CF application using VB.Net 2.0 and VS2005.
I am trying to create a heirarchy of controls to give my application
a
common look and feel.
Here is what I have so far:
public class ctrlBase inherits UserControl
public class tabBase inherits ctrlBase
public class pageMain inherits tabBase
When working with tabBase, I can correctly see the formatting and
controls on ctrlBase, and then add controls that should be accessable
to all decendants to tabBase. However, when I go into the designer
for pageMain, instead of seeing the controls from tabBase, I am again
presented with ctrlBase and its controls.
Is there some setting I need to make to allow inheritance deeper than
one level?
I appreciate any help you can offer.
Mike Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126974
Serialization Error
Has anyone had a serialization error occur when adding a variable to a
viewstate? The error states 'Error serializing value
'System.Data.SqlClient.SqlDataReader' . It does not mention
explicitly that it is from the viewstate, however, when I remove the
code for adding the data reader to the viewstate, I don't get the
error. I'm not having any luck trying to troubleshoot this online. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126968
Max pool size reached exception when trying to open a new connection
hi all,
i am working on a asp.net web app and using ado.net 's SqlClient Data
Provider to connect to
sqlserver 2005. I am getting the exception "Timeout expired. The
timeout period elapsed
prior to obtaining a connection from the pool. This may have occurred
because all pooled
connections were in use and max pool size was reached." . Internally i
am using a
sqldatareader to fetch data from database. The dispose of both the
reader and connection has
been called wherever they are being used. The pool size is set to
default i.e. 100. I have
tried to analyze the issue by using the sp_who2 stored procedure in
database and checking
the count of connections to the database.What is happpening is that
sometimes the pool size
limit is being maintained and increases 100. But on the other hand, it
sometimes shoot much
above the limit of 100 and then it throws the above mentioned
exception. Why does the
connection pooler sometimes enforces the pool size limit and sometimes
fails to do that
intrigues me.
But if i use GC.Collect in my code, then in that case the connection
pool limit is adhered
to and i dont get the above mentioned exception. Can someone please
help me with it and
explain why is it happening in the first place and is there a way
around it. I don't want to
use GC.Collect() in my code.
Thanks in advance
Ramneek Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126967
EnterpriseService deploy
Installing a pre-built .NET EnterpriseService on a winxp box results in the
follwoing error message: The typelib could not be loaded. The MSI package was
created on win2003 and exported there.
I can install 'n run the component on the winxp box. but I want to be able
to dcom it. What is wrong here? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126963
common config file
I have a server application which can be called by web services or
directly from the command line.
the solution has a website with web.config and a consoleProject with
app.config.
I need to work with a single config file (preventing duplication).
how can I do this? how can I load a common config file (that belongs
to a common project)? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126958
Client-side Data
Hi
there are 2 variables in PHP
$REMOTE_ADDR
$HTTP_REFERER
does anyone know what are the equivalent of these variables in ASP
TIA
Barry Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126952
WPF/E doesn't work in Windows 2000
The WPF/E doesn't work in Windows 2000 unsing IE6.
On the contrary it works on MAC OS.
I can't belive it.
Microsoft did a big mistake!
WPF/E MUST work in Windows 2000 unsing IE6.
What do you think about? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126951
XmlSerializer without namespaces?
Hi,
I'm using XmlSerializer objects to - surprise - serialize objects to xml.
My problem is that it includes the xml namespace references
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
for every single object which 1) isn't necessary in this case and 2) makes
the output xml more difficult to read. My question is: Is there a way to
avoid that?
Thanks!
Jens Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126949
How to Create WinForms client and ClassLib server as one assembly?
I'd like to break up my aplication into a WinForm executable, plus a class
library containing application utility functions. But I don't want any
client other than my own application to have access to my application
library. Isn't this the point of an 'assembly'? So how can I generate these
two artifacts as belonging to the same assembly? Is this possible with
Visual Studio 2005?
Thanks!
- Joe Geretz - Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126941
How to find connected adapter on win 2k
Win32_NetworkAdapter class has "NetConnectionStatus" and
"AdapterTypeID" properties.
I was thinking if i can iterate through all the adapters and will
check the NetConnectionStatus == connected. As soon as i will find
adapter connected i will get its AdapterTypeID.
But NetConnectionStatus is not supported on win2k.So can anyone
suggest me a way to find out Connected adapter type on 2k. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126940
Problem with .NET 2.0 sending mail with Password by NetworkCredential
I find below code or like in some sites (http://www.orcsweb.com/
articles/sending_smtp_authenticated_email.aspx)
my ISP announce that soon we need to give Authentication for sending
EMAIL. I add this code to my App, and I see that Even the Username &
Pass is not correct, the email send with no error. I try it with same
name & pass on OutlookExpress and I got Error. so it's seem to me that
this code not use with Credential that I give?
==================Heare the code
'Create a new MailMessage object and specify the "From" and "To"
addresses
Dim Email As New
System.Net.Mail.MailMessage("Brad.Kingsley@orcsweb.com",
"Brad@KingsleyTeam.com")
Email.Subject = "test subject"
Email.Body = "this is a test"
Dim mailClient As New System.Net.Mail.SmtpClient()
'This object stores the authentication values
Dim basicAuthenticationInfo As New
System.Net.NetworkCredential("username", "password")
'Put your own, or your ISPs, mail server name on this next line
mailClient.Host = "Mail.RemoteMailServer.com"
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email) Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126939
finding connected users in current ftp sessions programatically i
hi all,
i am trying to programatically get a list of connected users that in are the
current
ftp sessions tab in iis6.
i cant find anything on the net that seems to be able to help me, i've
looked at System.Net and various other places but there seems to be
nothing out there.
there are loads of posts about creating an ftp client however i want
to be able to talk to the iis ftp ( i already create ftp virtual
directories and user accounts on the fly and i want to know which of
these users in currently logged in and disconnect them if needed)
any help would be appreciated!
cheers
john Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126936
.NET Framework v3.0 x86 question
Hi,
I've seen a strange thing today.
Windows update proposed me to download and install "Microsoft .NET
Framework 3.0 Redistributable Package" for 50.8 Mb whereas on standard
MS website (http://download.microsoft.com" the same package is only 2.8 Mb.
So where is the problem ?
what does this version from Windows Update include ?
thanks a lot,
Al. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126934
Best way to pass string from Win32 to DotNet
Hello all,
What is the Best way to pass string (char*) from (Win32DLL) C/C++ to
(DotNet)C#?
Say if we allocate strings in win32 c++ dll in the heap (using new /
sysalloc - without using ATL/MFC bstr functions) Then how to
efficiently pass and consume them in the Dot Net environment C# and
VB.Net using the Dotnet String.
Also how to effectively deallocate that memory we use in between.
Kindly advise.
-Habib Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126932
Windows XP and HP all in 1 printer problems
I just bought a 7310 HP all in one and the software didn't install all the
way and the computer is not communicating with the printer for the scan and
fax modes but will communicate to print. The process of installation stops at
the window "waiting for device setup to finish". I had the same problem with
my other HP printer but learned to live with it. Thought a new one would
solve the problem. Also, when I click on the "add hardware" Icon the message
says that you can't install another device at this time because it's already
installing one---interesting. Am running windows XP, have a Sony computer
which is 1 1/2 yrs old. Of course I've reinstalled, checked the connections
etc. all the usual things. Do the HP all in ones just not work very well with
XP maybe and maybe I should try another brand. I appreciate any help. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126926
windows service and exe
I need to start an executable program from a web service. Then I need to
monitor it and ensure that it is still running. If it stops running, I need
to re-start it.
Any thoughts, and especially code examples would be great.
I am using Visual studio 2005 and C# Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126922
Windows XP games to Windows Server 2003
Can I download the games that come with Win XP OS to Win Server 2003
Enterprise?
If so where can I get the games file? I have Win XP Disc but no access to
load games. I'm getting bored!!!!!!! Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126916
String to byte[] reloaded
Hi
I need an efficient method to convert a string object to it's byte[]
equivalent.
I know there are LOTS of methods, but they lack in efficiency. All
methods allocate new memory to create the byte[] array. Of course,
when memory allocation occurs, then naturally extra processing power
is needed.
To more explicit, MFC introduced a super-efficient method of dealing
with this situation. As far as I remember (I switched from MFC
to .NET
few years ago), MFC's CString class has a method with the following
signature:
byte[] GetBuffer()
This method "blocks" the CString instance until ReleaseBuffer()
method
is called. Again, maybe the method names are not quite as I remember,
but the important thing is the principle.
The marvelous result is that you may freely iterate through the
byte[]
array returned by GetBuffer() method and even modify it (with respect
to some limits, of course), and all this, without allocating new
memory.
My question is: using MemoryStream class will do the job for me? I
mean, there is a method called GetBuffer(), but will it allocate new
memory or not, as it is not stated in MS documentation.
Thanks Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126915
DataGridViewCheckBoxColumn null/default value
Hi,
I'm using a DataGridView with some checkboxes
(DataGridViewCheckBoxColumn). It seems that the check box is
initialized to null. I set the TrueValue, FalseValue, and
IndeterminateValue to the appropriate values (true/false). But I
haven't found any property that sets the null value to false. As a
result, I always get NULL if no action was done on the checkbox.
I need to do the following-
1. How can I make the NULL value of the DataGridViewCheckBoxColumn to
indicate false.
2. How can I set the default value of the checkbox - i.e. when the
grid is loaded with the checkbox, it should be checked.
Any pointers in this direction would really be appreciated!
Thanks,
Juhi. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126912
Windows DST patch causes DateTime.IsDaylightSavingTime() to be incorrect for dates in past years
An interesting problem has arisen concerning the new Windows DST patches.
The rules seem to apply without regard to year. For example, run the
following C# code (assume you're running in the US Eastern time zone):
DateTime d = new DateTime(2006, 11, 1);
Console.WriteLine(d.ToString("dd MMM yyyy hh:mm tt zzz ") + " " +
d.IsDaylightSavingTime());
DateTime d2 = new DateTime(2007, 11, 1);
Console.WriteLine(d2.ToString("dd MMM yyyy hh:mm tt zzz ") + " " +
d2.IsDaylightSavingTime());
If the DST patch has been applied, you will get the following output:
01 Nov 2006 12:00 AM -04:00 True
01 Nov 2007 12:00 AM -04:00 True
The result for 1 Nov 2006 is incorrect -- it was not DST, but it would have
been had the new rules been in effect.
It appears that if the DST patch is applied, then for past years there is a
two week period in March/April, and a one week period in October/November
when IsDaylightSavingTime() will be incorrect, since during those periods
the new rules will yield incorrect results.
Does anyone know if Microsoft has any guidance for handling these anomalies?
Will there be another patch?
Wayne Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126910
Outlook Express message rules
How do I set up rule so that messages from parties who are not in my
approved sender list go to a special folder? Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126906
Size of an object
Hi, is there an easy way to know how much memory an instance of an object
takes?
I mean, there is the sizeof(type), but this is not what I want... the
sizeof(type) returns the size of all the members of the class, but if the
class contains reference types like a collection or a string, it can't
tell...
What I need to know is, if there is a collection of strings, with each
strings taking 100kb and having 5 strings in the collection, I want to have
500kb (or approx) as a return... is there an easy, thread-safe way?
Thanks
ThunderMusic
btw, I'm using c# with framework 2.0 Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126903
Temp Folder
I am trying to find something I swear I stumbled upon a few weeks ago.
I thought I saw something in the framework that provided the path to
the "...\Local Settings\Temp" folder. It also had a function for
creating a new folder within it. Can someone point me to this, or am I
just going crazy?
Thanks,
Mike Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126894
.NET Framework 1.1 and .NET Framework 1.1 Hotfix (KB886903)?
Hello,
I have a development machine (Windows XP SP2, all security updates/fixes,
20GB C partition, 60GB D partition) with Visual Studio 2003 and 2005
installed (I do dev work in both). I already have SP1 for .NET 1.1 and
VS2003 installed, but I want to install the latest SP1 release for Visual
Studio 2005, but it requires 6+GB of space on the C: drive. The problem is
that I only have about 4GB available on my C partition, so I am trying to
clean up.
On my development machine , I have two items listed in my Add/Remove
programs list:
Microsoft .NET Framework 1.1
and
Microsoft .NET Framework 1.1 Hotfix (KB886903)
Each of these take up about 1 GB each.
It sounds odd that in order to run the 1.1. framework (with sp1), I need
2+GB of storage.
Can I remove one of these components to free up some space WITHOUT affecting
the installation of 1.1 SP1?
Any other ideas for making some room (I have done all the standard stuff
like cleanmgr, etc.)??? I also have SQL Server 2005 installed, but all the
data files are on my D partition, not the default C drive.
TIA!!! Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126893
.NEt 2.0 : Threading questions
Hi,
I'd like to know what is the difference between the class AutoResetEvent and
ManualResetEvent.
Actually, I want to use the WebClient.DownloadString method to download 8
files simultaneously in order to concatenate the content of the 8 files (no
matter in which order).
How can I do that ?
What are the available class to reach my goal ?
Is this code snippet the best way ?
StringBuilder sb;
public void Do(string[] urls)
{
WebClient wc = new WebClient();
sb = new StringBuilder();
wc.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
AutoResetEvent[] threadSync = new AutoResetEvent[urls.Length];
for (int i = 0; i < urls.Length; i++)
{
threadSync[i] = new AutoResetEvent(true);
wc.DownloadStringAsync(
new Uri(urls[i]),
are
);
}
foreach (AutoResetEvent are in threadSync)
{
are.WaitOne();
}
context.Response.ContentType = "text/css";
}
private void wc_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
lock (sb)
{
sb.AppendLine(e.Result);
}
((AutoResetEvent)e.UserState).Set();
}
Thanks in advance,
Steve Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126885
How to protect package before unauthorized use
1. I'm searching information about indemnifying package before unauthorized
use.
2. How can i compare packages if are signed 2 same certificate and public
keys
Regards,
Nick Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126881
Question about Assembly.CreateInstance()
Here is my setup:
I want a plugin interface for my application.
I have my main app named App.exe
I have a plugin interface assembly named PluginInterface.dll (defines
IPluginInterface)
I have a plugin implementation named PluginTest.dll (defines TestClass)
In my application I simply do the following:
Assembly myAssembly = Assembly.LoadFile( "PluginTest.dll" );
IPluginInterface plugin = (IPluginInterface)myAssembly.CreateInstance(
"TestClass" );
plugin.Test() (one of the methods specified in the plugin interface).
I compile the code and I get the following:
MyApp.exe
PluginInterface.dll
PluginTest.dll
If I delete PluginInterface, My code won't run. Is there a way to
specify an interface w/o having to actually deploy a dll that just has
an interface specification in it?
Thanks,
Brad Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126873
Interop and Constants Problem
Hi,
I have built a VB.NET, VS 2005 class library that is exposed to VB6/COM
clients. Everything works as expected except for the fact that Constants
(Const) are NOT being exported to the VB6/COM type library; they are not
visible. I have tried every trick in the book to force .NET constants to be
available to VB6/COM, but to no avail. Enumerators appear correctly, but I
need String (Public Const Test As String = "MyString") type constants as
opposed to the numeric (Integer) type Enumerator members (Test = 5); I have
no choice, I cannot use Enumerators as they only store numeric values.
Is there any way to accomplish this. I basically want to avoid the
VB6/COM developer from having to guess which constant value to use; or if
there were to be a modification, that it would be available immediately.
Can anyone please help?
Regards,
Giovanni Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126868
CGI problem
Hi, i'm doing a console application, is a CGI program, every thing is
OK, but, when I add a Web Reference to a XML Web Service and try to
use a function from the Web Services the answer is always
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String
ns, CompilerParameters parameters, Evidence evidence)
at
System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[]
xmlMappings, Type[] types, String defaultNamespace, Evidence evidence,
CompilerParameters parameters, Assembly assembly, Hashtable
assemblies)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[]
xmlMappings, Type[] types, String defaultNamespace, String location,
Evidence evidence)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[]
mappings, Type type)
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
at test.EncrypServer.Service..ctor()
at test.Program.Main(String[] args)
Please, help me. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126865
how to specify private key to generate signature
Problem domain:
I need to generate a digitial signature for a file using a private key. The
receipient would have a public key, the generated digital signature and the
file to verify that the file has not been tamper with.
Question:
How do I specify the private key?
I have the following code:
private void Form1_Load(object sender, EventArgs e)
{
try
{
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
byte[] Data = Encoding.ASCII.GetBytes("hello world");
// assume its file content
byte[] HashedData = SHA1.Create().ComputeHash(Data);
byte[] Signature = dsa.CreateSignature(HashedData);
System.Diagnostics.Debug.WriteLine(BitConverter.ToString(Signature));
}
catch (System.Exception ex)
{
}
} Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126860
Running Applications
Is there a way using .Net to determine which applications are currently
running? For example, in Windows, if you press Alt-Tab, you will see a list
of applications currently running. I have looked at process.getprocesses,
but that returns all running processes instead of just applications. I would
like to fill a listbox with a list of applications (not processes) that are
currently running. Thanks. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126859
Reading an XMLFile
Hello all,
In the below XML:
- <comment_list description="Comment list">
- <comment description="Comment" item_no="1">
<date description="Date">2006-09-27</date>
<author description="Author">HKGE0406505.001</author>
<visible_to description="Visible to">P</visible_to>
<comment description="Comment">086095.</comment>
</comment>
- <comment description="Comment" item_no="2">
<date description="Date">2006-09-27</date>
<author description="Author">E0760.116</author>
<visible_to description="Visible to">P</visible_to>
<comment description="Comment">time adjuster</comment>
</comment>
</comment_list>
and using the below code
using (XmlReader reader = XmlReader.Create(@"c:\xml\isn_prod.XML-0139.xml"))
{
reader.MoveToContent();
reader.ReadToDescendant("claimkey");
sb.Append("ClaimKey: " + reader.GetAttribute("id"));
reader.ReadToFollowing("comment_list");
reader.ReadToDescendant("comment");
reader.ReadToDescendant("date");
sb.Append(" Date: " +
reader.ReadElementContentAsString());
sb.Append(" Author: " +
reader.ReadElementContentAsString());
reader.ReadToFollowing("visible_to");
sb.Append(" visible to: " +
reader.ReadElementContentAsString());
sb.Append(" comment: " +
reader.ReadElementContentAsString());
string a = sb.ToString();
}
I can happily navigate comment item number 2, but I can't seem to find a way
to get to the comment nodes (id=2).
Any help would be great,
Thanks,
Jon Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126855
How to pass global parms to web service???
I have a web service with several methods in it. When the user creates an
instance of this WS, I want to pass parameters to the instance:
localhost.WSdemographics myClass= new localhost.WSdemographics(string
Username, string Password);
Once the user creates this instance, then they can use the actual methods in
the service:
DataSet my DS = myClass.GetNames(int RecordGroup);
But when I go to create the instance of 'myClass' I do not get the 2
parameters in the intellisense. It wont even build, b/c it says the class
does not take parms, yet its defiend as
public class WSdemographics : System.Web.Services.WebService
{
public WSdemographics(stringUserName,string Password)
{
...
}
...//WebMethods
...
}
I dont want to have to pass the userName and Password to every moethod in
the service, just at the point its reference. Why cant this be done?
--
JP
.NET Software Developer Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126853
Wanting to read XML blob from configuration
I'm probably missing something because the .NET configuration model seems
pretty screwed up. Since the configuration file is an XML file it would seem
to make sense, at least to me, to have the reading/writing of configuration
information rely on the XmlSerializer. Instead they came up with a whole new
set of configuration attributes to do, I guess, the same (or similar) thing
the XmlSerialization attributes do. Why?
Getting to my question at hand, I plan to use the XmlSerializer to read data
from my application configuration file. I would like to be able to request a
section and get back an XmlNode for that section. I will then deserialize
that using the XmlSerializer. I was hoping that I could simply call
ConfigurationManager.GetSection(...) passing in my section name and get back
an XmlNode. However, that doesn't work. So after looking at all the derived
ConfigurationSection classes it appears as if the DefaultSection class will
allow me to get an XML string which represents the section. Is this true? I
was hoping to get an XmlNode because I was thinking that the framework had it
in that form and didn't want to have to serialize back to a string.
I was also surprised that there doesn't seem to be any way to
programmatically specify a configSection. I seems as if I'm stuck having to
do the following:
<configuration>
<configSections>
<section name="orderFill" type="System.Configuration.DefaultSection,
System.Configuration, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
...
</configuration>
It's kind of ugly and if I know in the code that I want to use the
DefaultSection why can't I somehow tell the framework at runtime that I want
to add a new configSection removing the need to specify it in the application
configuration file?
--
Thanks,
Nick
nicknospamdu@community.nospam
remove "nospam" change community. to msn.com Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126851
ClickOnce and proxy 407 error
Hello,
In our company, we would like to use ClickOnce which seems to be a very
efficient way to deploy application. So we made some small tests and we
quickly found the problem of the proxy 407 Error.
We looked for any solution on the internet but we only found that we have to
contact the support to replace the file System.Deployment.dll on the local
.Net framework to make it work. For the time being, we did not call the
support hoping there is another way to bypass this problem. We also tried to
configure the Localmachine.config file, but it did not work.
Do you know if a service pack for that will be available soon for the .Net
framework 2.0?
Do you have any news about this problem?
Thanks in advance for your answer,
Regards
Here is the Exception returned:
PLATFORM VERSION INFO
Windows : 5.0.2195.262144 (Win32NT)
Common Language Runtime : 2.0.50727.42
System.Deployment.dll : 2.0.50727.42 (RTM.050727-4200)
mscorwks.dll : 2.0.50727.42 (RTM.050727-4200)
dfdll.dll : 2.0.50727.42 (RTM.050727-4200)
dfshim.dll : 2.0.50727.42 (RTM.050727-4200)
SOURCES
Deployment url : http://serveur/ClickOnce/WindowsApplication2.application
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later
in the log.
* Activation of http://Serveur/ClickOnce/WindowsApplication2.application
resulted in exception. Following failure messages were detected:
+ Downloading http://Serveur/ClickOnce/WindowsApplication2.application did
not succeed.
+ The remote server returned an error: (407) Proxy Authentication Required.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [08/02/2007 17:13:26] : Activation of
http://Serveur/ClickOnce/WindowsApplication2.application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [08/02/2007 17:13:27]
System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading http://Serveur/ClickOnce/WindowsApplication2.application did
not succeed.
- Source: System.Deployment
- Stack trace:
at
System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at
System.Deployment.Application.FileDownloader.Download(SubscriptionState
subState)
at
System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri&
sourceUri, String targetPath, IDownloadNotification notification,
DownloadOptions options, ServerInformation& serverInformation)
at
System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore
subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState,
IDownloadNotification notification, DownloadOptions options,
ServerInformation& serverInformation)
at
System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore
subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState,
IDownloadNotification notification, DownloadOptions options)
at
System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut)
at
System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.Net.WebException
- The remote server returned an error: (407) Proxy Authentication Required.
- Source: System
- Stack trace:
at System.Net.HttpWebRequest.GetResponse()
at
System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126850
Controlling Windows Firewall from .Net
Hi,
I have written a service which listens on a particular port (using
remoting). The service runs under a user account with local admin rights.
This service will run on XP/Server 2003/Vista.
I need to either open the required port, or register my app with the Windows
Firewall so it can receive requests. How can I do this from my code? I'd
like to code a method to make the changes to the firewall when the servce is
running, and then undo the changes when the service stops.
I'm using VB.NET 2005
Cheers for any help
Stu Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126833
Is there a Generic Collection with events?
There's Collection<T>, but it doesn't have event hooks for items added or
removed. I was going to create a descendent that does just that, but before
I do, I want to make sure there isn't already something that exists in the
Framework.
Thanks,
Lee Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126826
Deadlock in XmlSerializer when using RedirectStandardInput
Problem
I have encountered a situation where a thread (say, thread-1) blocks for 10
minutes in the XmlSerializer constructor. This occurs when another thread
(say, thread-2) is blocked in a call to Console.ReadLine and the process was
created using System.Diagnostics.Process with RedirectStandardInput = true.
In this situation, not only does thread-1 block for 10 min in the
XmlSerializer constructor, but so will hang indefinitely when creating a COM
object.
The problem started occuring after migrating our application to .NET v2.0.
I found a forum post where some other developers have run into the exact
same problem. Please see this link:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=188895&SiteID=1 (it
also includes a reproducible testcase)
Background
We need to run multiple instances of an console application (it runs until
told to stop). Since we need to run more than one process on a single machine
it did not make sense to make the application a windows service. Instead we
developed a windows services that spawns these (child) application processes.
Using the System.Diagnostics.Process class we can not only spawn the process,
but interact with it via stdin and stdout.
(Not so nice) Workarounds
It appears that the XmlSerializer hangs in the call to csc.exe (you can see
this child process using ProcessExplorer). I can get around this problem by
sgen'ing the assembly which eliminates the need for spawning csc.exe at
runtime. However, this doesn't fix the problem with creating COM objects.
Another workaround i've seen (see forum post mentioned above) is to not call
Console.ReadLine(). However, I need this call in order to process interactive
commandline input. Also note the call to ReadLine is on an MTA thread, so
there should not be any STA "pumping" issues.
------------
Is anyone aware of a decent workaround to this issue (or a fix available
.NET 2.0)? I seems that this problem greatly limits the usefulness of stdin
redirection. Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126825
.Net runtime 2.0 error, Event id: 5000
Hi,
I have made some software that uses one of the COM ports to
communicate with an external device. The software is written in C# and
uses the new SerialPort class in .Net 2.0.
It works perfectly when I use the COM ports that are integrated in my
PC. It also works if I use a COM->RS232 converter as long as I don't
unplug the converter when the software is running. If I unplug the
converter I get a .Net runtime 2.0 error:
http://therkelsen.info/images/blandet/atrack_prob.JPG
This error makes the .Net runtime environment shut down my software
and it seems like there is nothing I can do about it. I can not catch
the "objectDisposedException" because it is thrown inside the .Net
environment and makes the environment crash.
Any ideas about what I can do to stop the framework from crashing?
Is this a known bug in the .Net framework?
Best regards,
Kim Therkelsen Tag: Download free ebook MCTS Exam : 70-431 ebook Tag: 126824
Download free ebook MCTS Exam : 70-431 ebook
Go to http://free-tech-ebooks.blogspot.com/2007/02/download-free-ebook-mcts-exam-70-431.html