.net

Why check this != null?

Occasionally I like to spend some time looking at the .NET code just to see how things are implemented behind the scenes. I stumbled upon this gem while looking at the String.Equals method via Reflector. C# [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public override bool Equals(object obj) { string strB = ob...

Detecting if the garbage collector was invoked (.Net)

When using SqlConnection, it's important to always close it when used - either by .Close() or placing the SqlConnection in a "using". Unfurtunately, people, including myself, tend to forgot that and this is where the garbage collectors rescues me for a while until i've forgot to close my connections too many times or the number of people...

C# - Removing Items from Dictionary in while loop

I have this and all seems to work fine but not sure why and if its valid. Dictionary<string, List<string>> test = new Dictionary<string, List<string>>(); while (test.Count > 0) { var obj = test.Last(); MyMethod(obj); test.Remove(obj.Key); } Update: Thanks for the ans...

VB "Financial.Pmt" equivalent in C#?

There is a built in function from the Microsoft.VisualBasic assembly. I can use it in VB like this: Financial.Pmt((dAPR / 100) / 12, iNumberOfPayments, dLoanAmount) * -1 My current project is in C# and I need to use this function. Answers on the web say just add the namespace and assembly and use the same in C#- but this is not true! ...

Having problem with WCF Service with static data.

Update: with help from Henk, determined that public Dispose() is being called, which in turn calls private Dispose(true). This is my first implementation of IDisposable interface, so not sure if it is correct. I don't call Dispose explicitly anywhere. It seems that WCF architecture is calling it on exit from each OperationContract mem...

How can I check if two different URL's point to the same resource?

Lets say I have a web site hosted on a computer named "linux" and it is part of two different networks with the addresses 192.168.1.1 and 10.1.1.1. When working locally on "linux", I can access this web site through the following URLs : http://192.168.1.1/ http://10.1.1.1/ http://linux/ http://localhost/ http://127.0.0.1/ Working o...

Where and how to use nested classes ?

Hello everybody I am thinking that if a class will be instantiated only in another class so it is right to use it nested in that class.I think this will help us good design.When i look at my project i have almost never seen such nested structure.But if i try to nested classes so this time another questions appear in my mind.For example ...

Why does the VS 2010 ASP .NET ReportViewer fail to render parameters when a custom RoleProvider is specified?

I have taken a sample SSRS report from http://gotreportviewer.com/. The report displays some customer data and the "City" parameter. The report also uses the "City" parameter to filter the data. This report runs just fine unless I enable a custom RoleProvider through web.config. I have set break points in all of the methods of my custom ...

.NET framework from a low level programmer's point of view

When I was learning .NET I saw it as a platform that runs my .NET programs which has its own Stack & Heap. But now after learning more about things, I see a .NET application as just like any other C/C++ native application. It is in Portable Executable (PE) file format with new data directory & .text section is filled with MSIL code in...

Migrating SharePoint 2007 to 2010

Is a sharepoint 2007 webpart likely to work on 2010 without any modification? If not, what are the main areas that would require modification? ...

WPF App loses completely focus on window close

Problem description If I make a non-modal window as a child window through setting the Owner of the window to a parent window, and then show a MessageBox from within this child window, the parent window will lose focus if I close the child window. If windows explorer or another app is open, this app will get the focus and my main window...

In what format is SQL Server data serialized when it is sent through the network?

The reason I am asking this question is because we are planning to read A LOT (several GB's) of data from a SQL Server database to a .Net app for processing. I would like to know how much space overhead to calculate for each record for estimating the impact on our network traffic. E.g. a record consists of 5 integers (which makes 4 * 5...

How do I get .NET's Path.Combine to convert forward slashes to backslashes?

I'm using Path.Combine like so: Path.Combine("test1/test2", "test3\\test4"); The output I get is: test1/test2\test3\test4 Notice how the forward slash doesn't get converted to a backslash. I know I can do string.Replace to change it, but is there a better way of doing this? ...

When I use "Add Service Reference", I can't see optional method parameters.

I'm working on a WCF Service. I have one service operation Function getValues(Optional verbose as Boolean) as List(of String). This works: ' First, add a file reference that contains the iRM interface. Dim ep3 As EndpointAddress ep3 = New EndpointAddress("net.pipe://localhost/RM/RMPipe") Dim netPipeR...

How should i refactor this?

so in my application I've got several different customers being "serviced". Each customer has their own implementations of various classes that are all based on interfaces. With the latest customer being added, I've noticed there will be a lot of duplication of code from another customer but the other customer is in no other way relate...

How do I execute LINQ queries against a database with varying schema?

I need to execute read-only queries against a database that I don't control. My top choice would be Linq to SQL, however, the column names differ slightly between our Dev, QA, and Production environments. For example, take a FolderName column. We might have: Dev: u34_FolderName QA: u74_FolderName PROD: u56_FolderName I want to d...

Why is this .net UIAutomation app leaking/pooling?

I've got an app using .net UIAutomation, it eventually runs out of memory and crashes just monitoring windows being shown and closed. Seemed easier to show this in VB than C# but happens the same either way. It appears to be a leak/pool in the underlying proxy objects. Most of the memory is not being shown as in use as .net memory. An...

asp.net: edit resource file which is compiled into a dll

Hi, my asp.net site uses resource files for a referenced project with the user controls in it. so i have one website project, and one dll project with usercontrols + the resource files. The website references the dll project. So far so good. When i publish, the dll with the usercontrols gets compiled in a dll (what else) but the res...

Passing DataTable over COM into R

Hello, I am trying to pass data from SQL, to C#, then to an R server for data analysis then back to my web application; however, the COM interface that I am using does not allow complex data types to be passed between C# and R (no data tables). I have gotten it to work in the past by using the following code: int count = dataTable....

Can I redirect .NET method calls to a new method at runtime?

Suppose I have the following .NET classes: public class C { public void M() { .... } } and public class D { public void N() { .... } } These 2 classes reside in different namespaces, in different assemblies. Is there a way to cause all call to C.M() to 'redirect' automatically to D.N()? So,...