.net

How to record window position in WinForms application settings

It seems like a standard requirement: next time the user launches the app, open the window in the same position and state as it was before. Here's my wish list: Window position same as it was Unless the screen has resized and the old position is now off screen. Splitters should retain their position Tab containers should retain their...

How do I call a .NET assembly from C/C++?

Suppose I am writing an application in C++ and C#. I want to write the low level parts in C++ and write the high level logic in C#. How can I load a .NET assembly from my C++ program and start calling methods and accessing the properties of my C# classes? ...

How do I Yield to the UI thread to update the UI while doing batch processing in a WinForm app?

I have a WinForms app written in C# with .NET 3.5. It runs a lengthy batch process. I want the app to update status of what the batch process is doing. What is the best way to update the UI? ...

What's the Meaning of and Fix for the Error 'The Controls Collection cannot...'

Using ASP.NET 2.0, I have a web app where I am trying to use Javascript to make one tab in a tabcontainer the active tab. The recommendations have been based on: var mX=document.getElementById('<%= tc1.ClientID%>') $find('<%= tc1.ClientID%>').set_activeTabIndex(1); Which both produce the error: The Controls collection cannot be mod...

What is your favorite Visual Studio add-in/setting?

What add-in/setting in Visual Studio can you not live without? Which one improves your productivity or fixes something you can't stand in Visual Studio? Why is it your favorite? My favorite is aspx edit helper because it does really improve my productivity when working with ASP.NET applications. What it does is provide a quick way to t...

Accessing an image in the projects resources?

How do I access an image during run time that I have added to the projects resources? I would like to be able to do something like this: if (value) { picBox1.image = Resources.imageA; } else { picBox2.image = Resources.imageB; } ...

Requiring users to update .NET

I'm working on some production software, using C# on the .NET framework. I really would like to be able to use LINQ on the project. I believe it requires .NET version 3.5 (correct me if I'm wrong). This application is a commercial software app, required to run on a client's work PC. Is it reasonable to assume they have .NET 3.5, or assum...

Enabling editing of primary key field in ASP.NET Dynamic Data / LINQ to SQL

If you have a table with a compound primary key that is composed of a foreign key and other table columns, how do you get ASP.NET Dynamic Data to allow the non-foreign primary key table columns to be editable? ...

What is the best way to debug stored procedures (and write sprocs that are easier to debug)?

What are good methodologies for creating sprocs that reduce the pain of debugging? And what tools are out there for debugging stored procedures? Perhaps most importantly, what are indications to look out for that errors are happening in a sproc and not in the code? I hope I'm not all over the board too terribly bad here. Votes for answe...

What is the most flexible serialization for .NET objects, yet simple to implement?

I would like to serialize and deserialize objects without having to worry about the entire class graph. Flexibility is key. I would like to be able to serialize any object passed to me without complete attributes needed throughout the entire object graph. That means that Binary Serialization is not an option as it only works with...

How to make sure a font exists before using it with .NET

I have a VB.NET Windows Forms project that at one point paints text directly to onto the form at runtime. Before I paint with the font though, I want to make sure that the font and font-size exists on the user's machine. If they don't, I'll try a few other similar fonts, eventually defaulting with Arial or something. What's the best way...

What do you use to protect your .NET code from reverse engineering?

For a while we were using a tool called CodeVeil. I'm just wondering if there are better alternatives out there. Edit: Before more people misunderstand the question, I'm aware that a determined cracker would probably be able to defeat any of these tools. I'm not too concerned about them though. These tools are just meant to stop the...

InternalsVisibleTo attribute isn't working

I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes in a .NET class library visible to my unit test project. For some reason, I keep getting an error message that says: 'MyClassName' is inaccessible due to its protection level Both assemblies are signed and I have the correct key listed in the ...

Should I use internal or public visibility by default?

I'm a pretty new C# and .Net developer. I recently created an MMC snapin using C# and was gratified by how easy it was to do, especially after hearing a lot of horror stories by some other developers in my organisation about how hard it is to do in C++. I pretty much went through the whole project at some point and made every instance o...

How do I read a file over a network that is in use/locked by another process in c#?

Is there a way to read a locked file across a network given that you are the machine admin on the remote machine? I haven't been able to read the locked file locally, and attempting it over the network adds another layer of difficulty. ...

What's the best way to pass data between concurrent threads in .NET?

I have two threads, one needs to poll a bunch of separate static resources looking for updates. The other one needs to get the data and store it in the database. How can thread 1 tell thread 2 that there is something to process? ...

Why is there no generic synchronized queue in .NET?

I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but the same method isn't available on Queue<T>. Does anyone know why? Seems kind of weird. ...

Can you use Reflector to get the source code of an app and then debug using that source code?

It seems like you could use a mashup of Relector and a Debugger to be able to debug any .NET app WITHOUT having the source code at all. Is this possible? Has anyone seen this before? ...

Can a console app stay alive until it has finished its work?

I've just read up on Thread.IsBackground and if I understand it correctly, when it's set to false the Thread is a foreground thread which means it should stay alive until it has finished working even though the app have been exited out. Now I tested this with a winform app and it works as expected but when used with a console app the pro...

Can you debug a .NET app with ONLY the source code of one file?

I want to debug an application in Visual Studio but I ONLY have the source code for 1 class. I only need to step through a single function in that file, but I don't understand what I need to do it. I think the steps are normally something like this: Open a file in VS Load in the "symbols" (.PDB file) Attach to the running process I...