.net

How do you apply a .net attribute to a return type

How do I apply the MarshalAsAttribute to the return type of the code below? public ISomething Foo() { return new MyFoo(); } ...

Should constructor variables pass direct to private fields or properties?

Now this is .NET but I am sure the principal should apply to all OOP language, to simplify I take .NET as an example: R# usually creator constructor and passing incoming variable to private field, which for me mi tend to pass it to Property. Any opinion on how the different and what is the best practice for that? ...

How do you get the state to which a (.net) form will be restored?

I have a windows application and I want to save the size, position and WindowState between sessions. There is one caveat however. If the state when closing is minimized then I want to restore to the last visible state, i.e. Normal if it was normal before being minimized or maximized if it was maximized. Is there a property, check, cal...

What does "Cannot evaluate expression because the code of the current method is optimized." mean?

I wrote some code with a lot of recursion, that takes quite a bit of time to complete. Whenever I "pause" the run to look at what's going on I get: Cannot evaluate expression because the code of the current method is optimized. I think I understand what that means. However, what puzzles me is that after I hit step, the cod...

Is there a way to embed a web control in a Windows application that renders using anything but Trident (IE)?

Hi, I have heard mention that some desktop applications are pretty much just wrappers for websites now. I have even had the occasional problem that has been best solved this way in the past and I can see it being really useful for current applications development. However, one problem I always seemed to run into was that the Web Site ...

how do i read a time value and then insert it into TimeSpan variables

how do i read a time value and then insert it into TimeSpan variables ...

Which program in Visual Studio lets me look into DLLs to see its API?

See the question. I want to see the methods and classes offered by a DLLs library. ...

Is it worth investing time in learning Visual Studio Macro System(usage-creation)?

I have used visual studio for a long time, but one feature I have never used is the Macro system. I saw a post where someone mentioned he used macros (no elaboration) so I was wondering is it really worth the time investing in learning how to create macros? If so what kind of stuff do you make? There was similar post(s), but i am try...

XML namespace problem in Visual Studio generated service reference

I'm connecting to a web service hosted by a third-party provider. I've added a service reference in my project to the web service, VS has generated all the references and classes needed. I'm connecting with this piece of code (client name and methods anonymized): using (var client = new Client()) { try { client.Ope...

Is there an easy way, to Port a Win32 App in Delphi 2009 to .NET ?

We want migrate from Delphi 7.0 to Delphi 2009, to stay up with a modern IDE and current technology. Our target platform is .NET. What is best way, to achieve this goal? ...

Invert Regex Matches

How would I invert .NET regex matches? I want to extract only the matched text, e.g. I want to extract all IMG tags from an HTML file, but only the image tags. ...

Given a date range (start and end dates), how can I count the days, excluding specified days of the week in .Net?

I'm creating a UI that allows the user the select a date range, and tick or un-tick the days of the week that apply within the date range. The date range controls are DateTimePickers, and the Days of the Week are CheckBoxes Here's a mock-up of the UI: From Date: (dtpDateFrom) To Date: (dtpDateTo) [y] Monday, [n] Tuesday, [y] We...

.NET Configuration (app.config/web.config/settings.settings)

I have a .NET application which has different configuration files for Debug and Release builds. E.g. the debug app.config file points to a development SQL Server which has debugging enabled and the release target points to the live SQL Server. There are also other settings, some of which are different in debug/release. I currently use t...

Show a ContextMenuStrip without it showing in the taskbar

I have found that when I execute the show() method for a contextmenustrip (a right click menu), if the position is outside that of the form it belongs to, it shows up on the taskbar also. I am trying to create a right click menu for when clicking on the notifyicon, but as the menu hovers above the system tray and not inside the form (as...

How do you retrieve a list of logged-in/connected users in .NET?

Here's the scenario: You have a Windows server that users remotely connect to via RDP. You want your program (which runs as a service) to know who is currently connected. This may or may not include an interactive console session. Please note that this is the not the same as just retrieving the current interactive user. I'm guessing t...

Which ORM for .NET would you recommend?

I haven't worked on a .NET project for a while (more than a year). Before I've never used an ORM for a .NET application. What are some of your takes on this? Does using one make sense? Which ones should I consider trying? ...

Deterministic dispose of ThreadStatic objects

The ThreadStatic attribute declares a static variable as unique-per-thread. Do you know an easy pattern to correctly dispose such variables? What we used before ThreadStatic is a ThreadContextManager. Every thread was allocated a ThreadContext which retained all thread-specific information. We spawned some threads and let them work. The...

Embedded Outlook View Control

I am trying to make an Outlook 2003 add-in using Visual Studio 2008 on Windows XP SP3 and Internet Explorer 7. My add-in is using custom Folder Home Page which displays my custom form, which wraps Outlook View Control. I get COM Exception with 'Exception from HRESULT: 0xXXXXXXXX' description every time when I try to set Folder property...

How to illustrate usage of volatile keyword in C#

I would like to code a little program which visually illustrates the behavior of the 'volatile' keyword. Ideally, it should be a program which performs concurrent access to a non volatile static field and which get incorrect behavior because of that. Adding the volatile keyword in the same program should fix the problem. That somethin...

.NET: SqlDataReader.Close or .Dispose results in Timeout Expired exception

When trying to call Close or Dispose on an SqlDataReader i get a timeout expired exception. If you have a DbConnection to SQL Server, you can reproduce it yourself with: String CRLF = "\r\n"; String sql = "SELECT * " + CRLF + "FROM (" + CRLF + " SELECT (a.Number * 256) + b.Number AS Number" + CRLF + " FROM master..spt_v...