.net

NHibernate without a session

We are building a translation application which reads data from one database and translates it into a completely different format. We will be using NHibernate to read from the source database which is not yet available. We want to test the translation core logic by dummying up a source object, pass it through our translation core, and ...

Hosting a WCF service to be consumed by multiple consumers, getting a FaultException.

I have one computer acting as a WCF service host. a client machine will have multiple client processes running, each also hosting WCF services on separate ports (5601, 5602, etc.). The client processes will handshake the host. Once the handshake is received, the host will send back some data. The client processes are spawned one after an...

F#: Converting a string into an array of bytes

I'm writing a simple rc4 encryption/decryption utility as a first project. I'm stuck on trying to convert the given string into an array of bytes that can then be manipulated by the core algorithm. How do you convert a string into an array of bytes in functional f#? //From another thread let private replace find (repl : string) (str : s...

Password-protect Excel file using CarlosAg.ExcelXmlWriter

How do you password protect an excel file that is being generated using the CarlosAg.ExcelXmlWriter (.NET C#)? ...

In C#, how do you convert the TimeSpan datatype to DateTime?

I'm converting a small MSAccess application to a web-based ASP.NET app, using C# 3.5. I was wondering what's the best way to work with dates in C#, when converting some of this VBA code over to C#. Here is an example of the VBA Code: Coverage1=IIf(IsNull([EffDate1]),0,IIf([CurrDate]<=[EndDate1],[CurrDate]-[EffDate1],[EndDate1]-[EffDat...

Is there a reasonable scenario for a stateful IComparer<T>?

I have never written a stateful IComparer<T> with a default constructor. All standard library implementations which I've checked in Reflector are stateless as well. Therefore, I'd like to assume that I can freely cache IComparer<T> like this: PriorityQueue<TPriority, TComparer> where TComparer : IComparer<TPriority>, new() { private...

Child GridView Hidden on Button Press, Needs to stay displayed.

Hi, I have a child GridView which is displayed when a user selects a row in a the parent GridView. What the user can do is select items in the Gridview, which then go off to a results page. However, what I have is a button on the page which when clicked shows the user what they have selected. The problem is that when the button is pr...

How to rollback OracleBulkCopy() inserted rows?

Hello, I have tried to roll back external transaction and also tried to abort OracleBulkCopy() but it still inserted all rows. Anyone knows how to do this? Case 1: Didn't work. All row inserted anyway. OracleConnection connection = new OracleConnection(ConnectionString); connection.Open(); OracleTransaction trans = connection.BeginTra...

Copying part of one XML DOM to another for XSL transformation (.NET)

The scope of XML and DOM in .NET 3.5 is so large that I'm having trouble coming up with a simple solution to my problem without using too many lines of messy code. Since people here always come up with some elegant solutions, I thought it would be a good question. How do I take in an XML file (that I created and saved earlier in the pro...

Learning about Hidden Features

Today I found out about an interface I'd never heard of before: IGrouping IEnumerable<IGrouping<YourCategory, YourDataItem>> I am fortunate to have access to some of the best programming books available, but seldom do I come across these kinds of gems in those books. Blogs and podcasts work, but that approach is somewhat scattershot....

How do I prevent my .Net dll from being added as a reference?

Say I've written a .Net dll and want to distribute it with my application. How can I prevent any user with the savvy to install a copy of VS from adding a reference to this dll to their own applications? ...

Sandcastle Topic Grouping

We're using Sandcastle to generate our source code documentation with our build process. This is working great for creating API level doc for classes, methods, properties, etc. Additionally, Sandcastle allows you to add summaries to your namespaces as well as "Conceptual Content". We're creating Conceptual Content files for various "H...

System.Management.ManagementEventWatcher - Recovering From Disconnection

I am attempting to build an application that can monitor multiple remote machines through WMI. As a C# developer, I have chosen to utilize the System.Management namespace. For performance and scalability reasons, I would much prefer to use an event-driven method of gathering information than a poll-based one. As such, I have been inve...

Bug in my datagridview EditingControlShowing handler (.NET)

I have a DataGridView and a handler for the EditingControlShowing event which is used to add or remove handlers for the keyUp event for some columns. The problem is sometimes a column which does not have an associated KeyUp handler actually fires the handler. It seems like the grid does not know which column is supposed to fire which ha...

How can I simulate a C++ union in C#?

I have a small question about structures with the LayoutKind.Explicit attribute set. I declared the struct as you can see, with a fieldTotal with 64 bits, being fieldFirst the first 32 bytes and fieldSecond the last 32 bytes. After setting both fieldfirst and fieldSecond to Int32.MaxValue, I'd expect fieldTotal to be Int64.MaxValue, whic...

Determine string literal escape characters in Ado.net

Given any DbConnection from any Data Provider, is it possible to determine the character or characters used to quote a string literal as well as escape any special characters within the string? I'm also interested in the characters necessary for quoting schema/table/column name identifiers. Using parameters to specify these things is no...

.NET Placement New

Is there a placement new in .NET (like C++)? In other words if I allocate some memory in VB.NET Dim Foo(64) as Byte I want to instance BarClass in the Foo memory (something like...) Dim Bar as New BarClass(Foo) However, I don't see any syntax to do this. Instead I have to do something like: Dim Foo(1) as BarClass Foo(0) = new...

(.net) Is there any intrinsic difference between .net Explicit structs and c++ unions?

That is the question. Is there anything you can do with c++ unions that you can't with c# Explicit structs? ...

DataGridView.DataSource does not have new row from the grid (.NET)

I have a datagridview which is initially bound to an empty datatable. Then the first row is populated by setting values to the columns of the grid's CurrentRow.DataBoundItem row. I enter a new row manually by typing values in the last blank row. I hit a save button which does: DataTable dt = (DataTable)MyGrid.DataSource....... I noticed...

Secure communications error. FTP

I'm trying to do a secure FTP file upload and keep getting errors. This is compounded by the fact that my target site is using a self signed certificate. I've tried ignoring any issues ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((obj, certificate, chain, policyErrors) => { retur...