.net-2.0

Fully understanding the .NET versions and backward compatibility

a 夏天 提交于 2019-12-05 18:16:29
问题 I have a .NET 2.0 application and I plan to make a 'smart installer' which checks for the available .NET version on the user's PC and install my specific port for it. I saw that: Windows XP (SP2) comes with .NET 2.0 Windows Vista comes with .NET 3.0 Windows 7 comes with .NET 3.5 Windows 8 comes with .NET 4.5 As far as I know, the only thing that's not backward compatible is the CLR version, which is changed after .NET 4.0. So if I don't want the user to install additional framework just for

How to set an Int16 value to a Nullable<Enum> property using reflection?

旧城冷巷雨未停 提交于 2019-12-05 16:22:04
I need to do this:- MyClass.cs using System; using System.Collections.Generic; using System.Text; namespace set_property__Enum_To_Nullable_Enum { public enum MyEnum : short { One, Two, Three } public class MyClass { public string MyStringProperty { get; set; } public MyEnum? MyEnumProperty { get; set; } public void ShowAll(string message) { Console.WriteLine(message); Console.WriteLine("String = " + MyStringProperty); Console.WriteLine("Enum = " + MyEnumProperty.Value); } } } Program.cs using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace set

ASP.Net using wrong web.config for virtual directory

﹥>﹥吖頭↗ 提交于 2019-12-05 15:54:52
We're running IIS 6 on Windows Server 2003 R2. We want to add a virtual directory that runs under .NET 4.0 to a site that runs under .NET 2.0. We've given the virtual directory its own app pool, and we've configured the virtual directory to run under 4.0. The parent site works fine, but the virtual directory throws errors that reference the parent site's web.config file. We need the virtual directory to use its own web.config file. The GUI in the IIS Manager says that the virtual directory is using its own web.config file, but the error messages we get refer to items in the parent's web.config

.NET 2.0 : File.AppendAllText(…) - Thread safe implementation

こ雲淡風輕ζ 提交于 2019-12-05 15:35:58
问题 As an exercise in idle curiosity more than anything else, consider the following simple logging class: internal static class Logging { private static object threadlock; static Logging() { threadlock = new object(); } internal static void WriteLog(string message) { try { lock (threadlock) { File.AppendAllText(@"C:\logfile.log", message); } } catch { ...handle logging errors... } } } Is the lock needed around File.AppendAllText(...) or is the method inherently thread-safe by its own

Dynamic WHERE clauses in a SqlDataSource

非 Y 不嫁゛ 提交于 2019-12-05 14:04:16
I'm using a SqlDataSource in a very simple application. I'm allowing the user to set several search parameters for the SDS's select command via TextBoxes, one TextBox per parameter (think txtFirstName, txtLastName, etc). I'm planning on using a button click event handler to set the SqlDataSource's SelectCommand property which by default will return all records (for my purposes here). I want to refine this select command to possibly add one or more WHERE clauses depending on if the user enters search criteria in any of my TextBoxes. Example in case I'm not being clear: By default, my

Nullable value with xsd.exe generated class

☆樱花仙子☆ 提交于 2019-12-05 12:24:16
问题 I have been using xsd.exe to generate a class for deserializing XML into. I have decimal value in the source xsd that is not required: <xs:attribute name="Balance" type="xs:decimal" use="optional" /> The resulting class from xsd generates the following code: private decimal balanceField; [System.Xml.Serialization.XmlAttributeAttribute()] public decimal Balance { get { return this.balanceField; } set { this.balanceField = value; } } Which I note is not nullable. How do I instead generate the

Web service variable shared for the lifetime of the webservice?

不打扰是莪最后的温柔 提交于 2019-12-05 12:21:07
How can I make a variable (object) available for the whole lifetime of the webservice? Static variable seem to work but is there an other way to do it? Static variables exist for the lifetime of the App Domain that contains them. In the case of a web service, this is usually the ASP.Net Worker Process. What that means is that when IIS decides to cycle the worker process, your static variable will be gone. This may be what you want, in which case it is probably a good choice. (Putting asside discussions of whether or not static variables are proper in a given context). Within the scope of a web

CLR 2.0 vs 4.0 performance?

房东的猫 提交于 2019-12-05 12:06:55
Will a .NET program compiled for CLR 2.0 run faster if running unden CLR 4.0? app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" /> <supportedRuntime version="v2.0.50727"/> </startup> </configuration> Typically, no - it will be identical. By default, the CLR 4 runtime will load the CLR 2 runtime to execute your CLR 2 code base. Forcing execution under CLR 4 requires setting useLegacyV2RuntimeActivationPolicy in your app.Config. If you add that flag, then it will run in v4 of the

How do I catch KeyUp event ? (sample of code, please)

£可爱£侵袭症+ 提交于 2019-12-05 11:49:29
I need to catch KeyDown & especially KeyUp events for 1,2,3,4,5,6,7,8,9 keyboard buttons. How does it do ? I can catch KeyDown event but what about KeyUp ? Please, provide some simple code. private void Form1_Load(object sender, EventArgs e) { this.KeyUp += new KeyEventHandler(Form1_KeyUp); } void Form1_KeyUp(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.NumPad1: break; case Keys.NumPad2: break; //... } } private void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Keys.D1) // number 1 { MessageBox.Show("Hello"); } } If you need the logic to be exactly the same

App is unable to write to the registry, even though the user has administrative privileges

╄→尐↘猪︶ㄣ 提交于 2019-12-05 10:20:03
I am using Visual Studio 2010, and I'm writing a program that needs to set (and read) new registry values under HKLM\Software\myapp The program is .NET 2.0-based and as for now it runs on Windows 7 64-bit. Here is my ocde: RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software", true); RegistryKey MyKey = softwareKey.CreateSubKey("MyApp"); RegistryKey = MyKey.CreateSubKey("MyKey"); selfPlacingWindowKey.SetValue("instaldateperson", datestr + usrname); The problem I have when running Visual Studio 2010, is that it will run the app but logged on as me, I am a user and member of