.net

How to throw custom exception when exception type was passed by constructor

I've created class that takes Exception type in constructor private readonly Exception _exception; public StringToObject(Exception exception) { _exception = exception; } i wanted to throw exception throw new _exception(""); but i got error: '._exception' is a 'field' but is used like a 'type' is any possib...

Word Spell Check pops up hidden and "freezes" my App

I am using Word's Spell Check in my in house WinForm app. My clients are all XP machines with Office 2007 and randomly the spell check suggestion box pops up behind the App and makes everything "appear" frozen as you cannot get at it. Suggestions? What do other people do to work around this or stop it altogether? Thanks Below is my ...

Why can't I see a DataGridView's properties?

Hi, I can't see DataGridView Properties in my C# program in Visual studio 2005. I can see the DataGridView on the Form - but can't see its Properties. Why ? Thanks in advance ...

Set CPU register values while debugging managed app in VS

I am debugging a .NET app in Visual Studio 2010 RC using disassembly view. The code is optimized and JIT-ed. At a particular point, I need to change ZR CPU flag so that JNE instruction would take a different path. For some strange reason, the registers window in VS is readonly and does not let me change register values, nor can I use "se...

Memory allocation for a class that has deep inheritance in .NET

If I have classes A, B, C, D, E, and interfaces like X, Y, Z, and model a system like: class B : A, X class C : B, Y class D : C, Z class E : D If A is an abstract base class and E is the class of interest, when I create an instance of E, would it in turn create instances of A, B, C, D, X, Y, Z in addition to E? If that's the case, w...

Ensuring that things run on the UI thread in WPF

I'm building a WPF application. I'm doing some async communication with the server side, and I use event aggregation with Prism on the client. Both these things results in new threads to be spawned which are not the UI thread. If I attempt to do "WPF operations" on these callback and event handler threads the world will fall apart, which...

Can VS 2005 build C# for .NET 4?

I am aware that you can probably build a lower version of .NET, but is it possible for me to build a project against the .NET framework version 4? ...

How do I use ProcessStartInfo to run a batch file?

But it doesn't work -meaning the java code is not executed. Although the batch file runs fine when clicked in Windows explorer or when run in command line .. Since this works fine when the batch file is a single DOS command, I think this is somehow related to the fact that the Java code needs ~20 minutes to run. I'm using the following ...

Is It possible to install or run dotnetredist.exe (or any arbitrary EXE) as part of an .MSI ?

Suppose I have an MSI, that has .NET Framework as a pre-requisite. I know the MSI generated from VS2008 setup project will detect when that pre-req is missing and will direct the user to install it. Q1. Is it possible, technically, to call out to dotnetredist.exe (or, I guess, any arbitrary EXE) during the run of an MSI, to handle this...

How to collect the new "Applications and Services Logs" found on Windows 7 or Windows Server 2008 using WMI?

In Windows Server 2008 and Windows 7 there are new Events categorized under "Applications and Services Logs". There is also a subfolder called Microsoft which has tons of subfolders as well. Is there any way to collect these events through WMI? For the regular "Windows Logs" such as Application and Security, it is possible to use the Wi...

Simple regex question to parse similar things in .NET?

Is there a way to gather all links that has a specific domain in a string where they only include ones that are either: href="http://yahoo.com/media/news.html" or >http://yahoo.com/media/news.html&lt; So basically links either prefixed by href=" and ends with " or links that are surrounded by ><. I tried to use Regex ( "href=\"(...

Passing c++ map data to c#

I have a map (enum, vector< double >) in c++ code that I want to access from a c# application. This is legacy code, so I'm limited to using COM objects to pass information. Currently we pass in one enum at a time to c++, and get back one vector at a time as a SAFEARRAY. I tried passing in a SAFEARRAY of enums, and returning a SAFEARRAY...

.NET isolated storage file locking throws NRE

So I am trying to lock an isolated storage file in my C# client application, so that multiple copies of my application are not able to access it at the same time. I am using the following syntax: lockStream = new IsolatedStorageFileStream("my.lck", FileMode.OpenOrCreate, isoStore); lockStream.Lock(0, 0); This code causes my applicatio...

Error checking in .NET with SQL 2005

Can I throw an exception on the SQL 2005 server so that I can catch it in C# code with SqlCommand.ExecuteQuery()? ...

How to Encrypt in C# .NET same as Java code

I need to send an encrypted string from a private key to a webserver for authentication. I have Java client code that generates the encrypted string correctly (such that the webserver can decrypt it with the public key). I am trying to write C# code to perform the exact same encryption - but have not succeeded. First a keystore was ge...

Am I calling a .NET object or a COM object?

An interesting question arose today. Let's say I have a .NET object that implements a certain interface IMyInterface and is also COM Visible. Now, I load the type from its ProgID and cast to a strongly-typed interface, like so: IMyInterface objEarlyBound = null; Type t = Type.GetTypeFromProgID("My.ProgId"); objLateBound = Activator.Cre...

.NET: How to binary serialize an object with attribute [DataContract]?

Class marked as [DataContract] can't be ISerializable at the same time. OK, so how can I serialize this type of object to a binary stream? private byte[] GetRoomAsBinary(Room room) { MemoryStream stream = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(stream, room...

How do I return a char* array from a clr assembly?

I have a simple managed C++ assembly which I am providing unmanaged wrappers for some static methods I have in a C# assembly. One of these methods returns a string which I have converted to a "const char*" type in the C++ assembly. The trouble I am having is that when I load this dll from an unmanaged source, I get bad data back in the p...

Resolving concurrency problem around collections

Hi, I'm having issues with concurrent usage of a shared collection with a multi-player synchronous game I'm working on. I did some digging around and found a neat thread-safe IEnumerator/IList implementation on Alexey Drobyshevsky's post on codeproject here: http://www.codeproject.com/KB/cs/safe_enumerable.aspx After adopting his impl...

What type to make child object of reference data?

I have an Object CaseNote which has numerous child object's like CaseNoteContactType. For 1 CaseNote there can be x CaseNoteContactType's. In the UI ContactTypes are shown in a CheckListBox. My question is how do I represent the ContactType child object? It is a simple int|string pair. public Class CaseNote { public Guid CaseNote...