.net

MSDTC problem with transactions in ADO.NET Entity Framework

Hi, in our current project we are using ADO.NET Entity Framework as data layer for the application. There are some tasks which require to run in a transaction because there's a lot of work to do in the database. I am using a TransactionScope to surround those tasks. using (TransactionScope transactionScope = new TransactionScope(Transa...

How to suppress/catch System.ObjectDisposedException?

I have an application that sporadically throws this exception: System.ObjectDisposedException: Cannot access a disposed object. Object name: "Panel". bei System.Windows.Forms.Control.CreateHandle() bei System.Windows.Forms.Control.get_Handle() bei System.Windows.Forms.ContainerControl.FocusActiveControlInternal() bei Sys...

When, if ever, would you expect classes marked as obsolete to be removed from the .NET framework?

As we approach the 4th major release of the .NET framework we are likely to see an increase in the number of classes and methods marked as obsolete (to indicate they are deprecated). I found this page listing all the obsolete members and types, which is growing quite large now. So, I was wondering whether: Have any members or types ma...

.Net4, Monitor.Enter(lockObject, acquiredLock)

In .Net4, Monitor.Enter(Object) is marked as obsolete : [ObsoleteAttribute("This method does not allow its caller to reliably release the lock. Please use an overload with a lockTaken argument instead.")] public static void Enter( Object obj ) And there is a new method Monitor.Enter(lockObject, acquiredLock) with this usage : bo...

Assembly.CodeBase: when is it no file-URI?

Assembly.Location gives a plain path to the assembly. Unfortunately this is empty when running in a shadowed environment, such as unit test or ASP.NET. Hovever, the Codebase property is available and provides a URI that can be used instead. In which cases it returns no URI starting with file:///? Or in other words: what are the cases in ...

System.IO.DriveInfo.GetDrives() hangs with disconnected network drives

Hi, I am writing a file manager in .NET 3.5. At startup, the application must enumerate available drives. I am using DriveInfo.GetDrives to do that. Unfortunately my users lamented that, when they have disconnected network drives, the application took about 30 seconds to start. I discovered that the GetDrives() function hangs for many...

C# Transparent Form in Panel

Hi there, im trying to create a semi-transparent form which is displayed in a panel. i can display the form in the panel but the opacity property wont work and the form is non-transparent. private void button1_Click(object sender, EventArgs e) { Form fr = new Form(); fr.FormBorderStyle = FormBorderStyle.None; fr.BackCo...

Insert OpenXmlElement after word bookmark in Open XML SDK

I was able to access a bookmark in my word document using this code: var res = from bm in mainPart.Document.Body.Descendants<BookmarkStart>() where bm.Name == "BookmarkName" select bm; Now I want to insert a paragraph and a table after this bookmark. How do I do that? (exampl...

What is the accepted practice for adding Nunit tests to an existing solution?

I have inherited a reasonable sized ASP.net solution that has no automated tests. The solution seems to include all of the source/pages in one solution with no name-spacing and no separation of tiers, so there are direct SQL calls within code behind files etc. Before making changes to this site I would like to add some unit tests, prefe...

Virtual Devices in Windows

I'm trying to write a remote control application which should allow a user to control a pc with a wireless device. It should be possible to use the device for example as game controller. I've got the advice to create a virtual device but I couldn't find any information on how to do that. What possibilities do I have to do that in Java or...

Update Struct in foreach loop in C#

I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing { public string Name; } class Program { static void Main(string[] args) { List<Thing> things = new List<Thing>(); foreach (Thing t in things) // for each fil...

Typical IoC container usage - passing data down the line

I've recently started using an IoC container for the first time, but I'm not educated on the best practices for using it. More specificaly I'm using Unity in a C# .NET project, and I started using it because it came with Prism. I use the container to resolve the "top level" objects, and they get the correct objects injected based on the...

Problem in the connection string of Microsof SQL Server 2005 !

Hi, I have MSSQLServer 2005 installed on my machine. I am creating a connection string like this: String sqlConnectionString= user id=admin; password=admin; server=MachineName\MSSQLSERVER; Trusted_Connection=no; database=MYDataBase; connection timeout=30 When I do: myConnection = new SqlConnection(sqlConnectionString); myConnection.O...

When using Aggregate objects do you use custom collections for the associations or not ?

For example is it better to have: public class Case : EntityIdentifiable { public Jobs Jobs { get; set; } public Vehicles Vehicles { get; set; } public Locations Locations {get;set;} public IDistances Distances { get; set; } } or public class Case : EntityIdentifiable { public Dictionary<string,Job> { get; set; ...

File extensions and MIME Types in .NET

I want to get a MIME Content-Type from a given extension (preferably without accessing the physical file). I have seen some questions about this and the methods described to perform this can be resumed in: Use registry information. Use urlmon.dll's FindMimeFromData. Use IIS information. Roll your own MIME mapping function. Based on thi...

Static field and Object reference not set to an instance of an object

I have a static field in a non static class. public class DBtools { public static string ConString ="XXXXXXXXX"; } This field is assigned to property in the code. SqlDataSource1.ConnectionString = DBtools.ConString; But after i run this app I'm getting a error Object reference not set to an instance of an object How come this...

C# Regular Expression Help

Given the following strings 7;#User One 7;#User Two;#9;#User Two 7;#User Two;#9;#User Two;#123;#User Three I would like to build a regular expression that "breaks" these apart so that each string returns the following matches: ["7;#User One"] ["7;#User Two", "9;#User Two"] ["7;#User Two", "9;#User Two", "123;#User Three"] I tried a...

Can I have a variable number of generic parameters?

In my project I have the following three interfaces, which are implemented by classes that manage merging of a variety of business objects that have different structures. public interface IMerger<TSource, TDestination> { TDestination Merge(TSource source, TDestination destination); } public interface ITwoWayMerger<TSource1, TSource...

SQL Server Compact 'Data Directory' macro in Connection String - more info needed

So, as described on this msdn page, when you define a Connection String for SQL Server Compact 3.5, you can use the "Data Directory" macro, like this: quote from this msdn page: Data Directory Support SQL Server Compact 3.5 now supports the Data Directory macro. This means that if you add the string |DataDirectory| (enclosed in p...

How to get server name through code if SQL Server (Standard Edition) is installed.

How to get server name through code if SQL Server (Standard Edition) is installed. We pass the server name while creating a connection string to connect SQL Server. Can we retrieve this value through code? string sqlConnectionString = string.Format( "user id={0};password={1};server={2};Trusted_Connection=no;database=TestDB; connection ...