.net

How can I use Rhino Mocks to mock a MEF export?

With reference to the Managed Extensibility Framework (MEF), I'm trying to work out how to create clean tests with mocks. I have an exported component which has three private imports. Each imported object (field) needs to be mocked. Given that the CompositionContainer uses fancy reflection tactics to set imported private fields of compo...

Redefining C# keywords?

Is it possible to redefine a C# keyword like int to use Int64 instead of Int32? If not, how can one do this? I want to have the flexibility to redefine the int I use, so later I could change it to int64 if I wanted, instead of going around to replace all the int values manually. ...

Get Application's Window Handles

Hello Guys, I'm bulding an app that given another app mainWindowhandle it collects information about the window state, I've no problem collecting information about child windows but, I can not access the other open windows of an application or even the menus... Is there any way of getting all window handles of an application ? Any ideas...

Simulating a locked/hung application

I have an application that interacts with another application using SendMessage (among other things). Everything works fine until the other application hangs (either because it has actually frozen or it is doing a long, blocking call). I would like to simulate an application hanging using a C# WinForms application. Is there any way to st...

Duplicating a stream

Hi, I have a producer which provides a System.IO.Stream instance. I also have several clients which consume this stream. Is it possible to give each client a "private view" of the stream? For example, if clientA reads from the stream, it doesn't affect the position clientB sees (i.e. if clientB start reading from the stream, it gets th...

Free/OpenSource .NET Diff generator?

I'm looking for a free library that can take two strings and produce a diff much like the diff's you see on edit revisions here on SO. I'm hoping one exists, as this is a trivial part of an app I'm working on and I'd hate to waste time reinventing the wheel. Any suggestions? ...

Resources for writing a C# Compiler for class?

I'm interested in writing a compiler for a intermediate byte-code language like C# (a subset of). I'm trying to accumulate all the resources and information I can before the project begins. I'll be writing the compiler in C# as well, so hopefully down the line my compiler will be able to dogfood itself. The best resource I have found ...

Embedded Form in a control or Form as User Control

Okay I have a large CRUD app that uses tabs with Forms embedded in them like so --> public static void ShowFormInContainerControl(Control ctl, Form frm) { frm.TopLevel = false; frm.FormBorderStyle = FormBorderStyle.None; frm.Dock = DockStyle.Fill; frm.Visible = true; ctl.Controls.Add(frm); ...

WindowsIdentity.GetAnonymous()

Hi Could you please explain me what is the anonymous identity used for? As far as I know windows does not have an anonymous account type ?! Kind Regards PK ...

Can I reset a static/shared class?

I've got a shared class (static in C#) which mostly carries some settings data that any class in the application can read and sometimes write. Also there are some static properties which holds some internal states. Now I want to revert this class to initial stage of it. With all default variables etc. Assume that the user want to reset ...

Why are Console.In Console.Out & Console.Error Properties Read Only?

Does anybody know why the Console.In, Console.Out and Console.Error properties are read only? One would probably assume because Microsoft didn't intend on having anybody change them, but the framework includes related Console.SetIn(), Console.SetOut() and Console.SetError() methods. Was there a valid reason for this or just a silly mist...

Datagrid scrolling in Windows s Mobile way to get rid of scroll bar?

I have a very simple form using the compact framework. I have two search fields a search button and a datagrid. The button sets the DataSource for a DataGrid on the form. I know that I can set the height and width on the DataGrid but I don't want the user to have to use the scroll bars on the DataGrid as it has a few hundred records. ...

XmlReader get element default from schema

This is probably a naive question about XmlReader, but I haven't turned up an answer in the MSDN docs. Suppose that I have XSD SchemaTest.xsd <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; <xs:element name="pageSettings"> <xs:complexType> <xs:sequence> <xs:element n...

Filter Replication set by username

I have a Merge Replication setup between a central server and 200 clients. The vast majority of the clients do not need all 5000 client records. Only the 50 or so that are assigned to them. How would I go about applying a Filter based on who's logged in? Should I create a NEW DB that maps user names to Client Records and go down that...

VB.NET / VSTO2008 fails; can't find runtime.

I'm trying to deploy a VB.NET app which is an extension to Excel using VSTO. It works fine in the development environment, but when someone else (without a dev environment installed, just the .NET framework) installs it, they get: The common language runtime could not be loaded by <application>. Contact your administrator for furthe...

Sql Server 2008 Closing Connections after database dropped

I am having problems with SQL Server dropping a connection after I have dropped and re-created a given database and the next time I try to execute a command against a new connection on that same database, I get: A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - ...

Encrypting/Decrypting an SMTP Password in a Client/Server App

I have a client app that needs to save a username/password for an SMTP Server. This data will be going into SQL Server 2005, and consumed by my server app. The server app will use the System.Net.Mail namespace to send e-mail messages using the supplied credentials (and from that user's e-mail address). How can I encrypt/decrypt the passw...

How can I specify the latest time of day with DateTime

I am using a System.DateTime object to allow a user to select a date range. The user is only able to select a date (not time) using a third party calendar so I will need to automatically specify the time of day it should use (ie: 00:00:00 or 23:59:59) after the date is chosen. How can I specify the time after the date is already stored ...

Is it possible to trigger a "fake" scroll progmatically in WinForms?

Is it possible to trigger a "fake" scroll progmatically in WinForms? The scenario: A form with various drawings on it done with System.Drawing (and no scrollbars). What I would like: Progmatically tell the Form the user has scrolled by 10 pixels to the left. The Form moves the existing drawing 10 pixels to the left. The Form generate...

Should AcceptChanges() be called every time a new row is added?

Which is recommended while (reader.Read()) { table.Rows.Add( new object[] { reader[0], reader[1], reader[2], reader[3] } ); table.AcceptChanges(); } or while (reader.Read()) { table.Rows.Add( new object[] { reader[0], reader[1], reader[2], reader[3] } ); } table.AcceptChanges(); ...