.net

What are the more advanced rules needed for your code to become CLS-complaint?

Here is a specific example which is not CLS-complaint according to VS.NET 2005. Public Interface IDbId Function GetNativeObject() As Object Function Equals(ByVal compObj As IDbId) As Boolean Function CompareTo(ByVal compObj As IDbId) As Integer Function ToString() As String End Interface This is an interface I implement with cla...

Creating new Soap Web Service with .NET 3.5

Hello All, I haven't really looked into the new .NET stuff since 2.0, but I'm wondering what the preffered way is for creating Web Services is now (SOAP, not RESTful). I remember in the old days, you created a ASP.NET Web Service. Now, I've been looking at WCF, but it seems like there's some added complexity. I've GOOGLED for some ...

"Atomically" changing a System.Threading.Timer

Let's say I have an existing System.Threading.Timer instance and I'd like to call Change on it to push it's firing time back: var timer = new Timer(DelayCallback, null, 10000, Timeout.Infinite); // ... (sometime later but before DelayCallback has executed) timer.Change(20000, Timeout.Infinite); I'm using this timer to perform an "idle...

simple linq to sql has no supported translation to SQL.

i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from p in db.Posts let categories = GetCategoriesByPostId(p.PostId) let comments = GetCommentsByPostId(p.PostId) select new Subnus.MVC.Data.Model.Post ...

I'm looking for a way to search the values in a .net hashtable using wildcards

I've got a whole host of values stored in a .net 2.0 hashtable. What I would really like to find is a way to, essentially, do a SQL select statement on the table. Meaning, I'd like to get a list of keys whose associated values match a very simple text pattern (along the lines of "starts with a number".) The final goal will be to remo...

ASP.NET MVC: How to Route Search Term with . (Period) at the end

I get a 404 response from .Net MVC when I try to make a request where my search term ends with a . (period). This is the route that I'm using: routes.MapRoute( "Json", "Remote.mvc/{action}/{searchTerm}/{count}", new { controller="Remote", count=10} ); The search works fine wi...

Maintain scroll position of treeview

How can I maintain the scroll position of a treeview control in .NET application? For example, I have a treeview control and go through a process of adding various nodes to it tacking them on to the bottom. During this process, I can scroll through the treeview and view different nodes. The problem is when the process completes, the tree...

How costly is boxing when explicitly implementing an interface

The current guidlelines for explicit member implementation recommend: Using explicit members to approximate private interface implementations. If you need to implement an interface for only infrastructure reasons and you never expect developers to directly call methods on that interface from this type then implement the members explici...

VB.NET Extension Methods

Hi, when I apply the tag above my methods I get the error Type System.Runtime.CompilerServices.Extension is not defined. Here is my sample <System.Runtime.CompilerServices.Extension()> _ Public Sub test() End Sub Where am I going wrong? Edit ~ Straight from the MSDN Article here, the same error Imports System.Runtim...

What is the purpose of LongLength for .Net Arrays?

What is the purpose of the LongLength property for arrays in .Net. Using a standard integer for length, you could accommodate up to 2 billion indices. Are there really people using .Net to maintain a single array with more the 2 billion elements. Even if each element was a single byte, that would still be 2 GB of data. Is it feasibl...

What is the best Windows Server 2008 configuration for a .NET development environment?

I want to give Windows Server 2008 a try as a .NET developer and a database environment. I was wondering which configuration would be the most appropriate for the server in terms of: Services: Which ones are unnecessary and can be turned off to increase performance? Software: What software fits the best with the server and are good to...

Detecting that a DB Connection is in error

As part of our unit tests, we restore a blank database when the tests start . The unit tests then perform their tests by calling web services (hosted in the Visual Studio ASP.NET host). This works fine for us the first time the unit tests are run, however if they are re-run without restarting the web services, an exception is raised as...

Regarding Passing Many Parameters.

I have around 8-9 parameters to pass in a function which returns an array. I would like to know that its better to pass those parameters directly in the function or pass an array instead? Which will be a better way and why? ...

Is there a UPnP Library for .NET (C# or VB.NET)?

I'm working on a P2P application, and I need to get it to communicate through NAT Routers / Firewalls using UPnP. However, it doesn't seem that the .NET Framework includes support for UPnP. Is there a UPnP Library for .NET? C# or VB.NET? UPDATE: I have since found the NATUPnP 1.0 Type Library (NATUPNP.DLL) COM Component that is part of...

Common C# source code for Windows and Windows Mobile

I have a goal to build an application with UI that would run on both Windows Mobile and "normal" desktop Windows. The priority is for it to "look good" under Windows Mobile, and for desktop Windows it is OK if it distorted. Before I invest days trying, I would like to hear if that is possible to begin with. There are several parts to thi...

Is there a way of making strings file-path safe in c#?

My program will take arbitrary strings from the internet and use them for file names. Is there a simple way to remove the bad characters from these strings or do I need to write a custom function for this? ...

Singleton vs Static Class for exposing data read from xml

Hi, We have a PageRoles xml file which contains the page path and the user role that can access that page. We are maintaining a Dictionary in a static class, which gets loaded int static constructor for the class. The class has a method CheckIfRoleAllowed that takes in a page path and returns a bool. Each page call the CheckIfRoleAllo...

Match an end html tag if start tag is not present

i want to get an ending html tag like </EM> only if somewhere before it i.e. before any previous tags or text there is no starting <EM> tag my sample string is ddd d<STRONG>dfdsdsd dsdsddd<EM>ss</EM>r and</EM>and strong</STRONG> in this string the output should be </EM> and this also the second </EM> because it lacks the starting <EM...

Directory Watch Class (.net)

I need a quick yes/no answer on this... Is it possible to get a Directory Watch Class to watch a directory and its sub directories (all the way down) or does the Directory Watch Class only monitor changes/events in the parent directory? ...

In C#, how can I downcast a previously upcasted object without knowing it's type?

I have an interface method public void Execute(ICommand command); which needs to pass known subtypes of ICommand to an apropriate Handle(SpecificCommand command) method implementation and do some generic handling of unknown types. I am looking for a universal (i.e. not requiring a giant switch) method of doing so, something similar ...