.net-4.0

Project Reference Problem, Visual Studio 2010

假装没事ソ 提交于 2019-12-05 10:27:05
问题 I have a solution that has one class library project, and the others are WPF applications. I have added class library's reference the but, but both of them cannot use its classes. So, what is the problem? NOTE: sorry for tags, it's safari's problem. 回答1: Make sure that all your projects target same Framework. It may be a case that your library class project targets full .Net Framework 4.0 while your wpf projects target .Net Framework 4.0 Client Profile. To do that go to project properties of

Can I iterate over the .NET4 MemoryCache?

ε祈祈猫儿з 提交于 2019-12-05 10:12:44
问题 I'm using the cache provided by System.Runtime.Caching.MemoryCache . I'd like to enumerate over the cache's items so that I can invalidate (evict then reload) items as such foreach (var item in MemoryCache.Default) { item.invalidate() } But the official docs found here state: !Important: Retrieving an enumerator for a MemoryCache instance is a resource-intensive and blocking operation. Therefore, the enumerator should not be used in production applications. Surely there must be a simple and

.net construct for while loop with timeout

安稳与你 提交于 2019-12-05 09:50:52
问题 I commonly employ a while loop that continues to try some operation until either the operation succeeds or a timeout has elapsed: bool success = false int elapsed = 0 while( ( !success ) && ( elapsed < 10000 ) ) { Thread.sleep( 1000 ); elapsed += 1000; success = ... some operation ... } I know there a couple of way to implement this, but the basic point is that I repeatedly try some operation with a sleep until success or I've slept too long in aggregate. Is there a built-in .net class/method

This SqlTransaction has completed; it is no longer usable

南笙酒味 提交于 2019-12-05 07:50:51
I am using Linq to SQL with SQL Server 2008 SP2, my application is WinForm .net 4 I am importing into SQL Server 200,000 records. I am creating the objects and attach them to the datacontext on the "insertonsubmit". I then do "submitChanges" every 100 records. I have NO TRANSACTION what so ever. I get this error "This SqlTransaction has completed; it is no longer usable." with stack at System.Data.SqlClient.SqlTransaction.ZombieCheck() at System.Data.SqlClient.SqlTransaction.Rollback() at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) at System.Data.Linq.DataContext

Can application built with .NET 4.5 run on .NET 4.0?

回眸只為那壹抹淺笑 提交于 2019-12-05 07:31:01
My project is targeting to .NET 4.5. It doesn't use any new 4.5 methods, so it actually works fine on the machine with only .NET 4.0 installed. This is all good until I added some extension methods and reflection. Then when I ran this .NET 4.5 program on the 4.0 machine, it failed with "System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly mscorlib". The famous ExtensionAttribute program that has been documented well here . Another quick way to test this is to add the following line. Then the program will throw the exception when

Using MSpec runner in Visual Studio 2010 and .NET 4

送分小仙女□ 提交于 2019-12-05 07:25:50
I'm a big fan of MSpec so naturally I wanted to use is right away with VS2010 as well. I have the MSpec runner defined as an external tool in Visual Studio to be able to have it always visible as a toolbar item. Anyway, whenever I try to use the MSpec runner (mspec.exe) with a .NET 4.0 solution I get the following error: Could not load file or assembly 'file:///C:\Users\[SOMEUSER]\[SOME_FOLDERS]\bin\Debug\[PROJECT].Specs.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. I can still run my specs with the Resharper

ThreadPool and sending emails

社会主义新天地 提交于 2019-12-05 06:55:32
问题 We are currently sending emails to users asynchronoulsy using the ThreadPool. Essentially, we have logic that comes down to this: for (int i=0 < i < numUsers; i++) { //Pre email processing unrelated to sending email string subject = GetSubject(); string message = GetMessage(); string emailAddress = GetEmailAddress(); EmailObj emailObj = new EmailObj { subject = subject, message = message, emailAddress = emailAddress }; bool sent = ThreadPool.QueueUserWorkItem(new WaitCallback(SendEmail),

Timer initialization and Race condition in c#?

一笑奈何 提交于 2019-12-05 06:40:45
I saw this code on Richter's book : The following code demonstrates how to have a thread pool thread call a method starting immediately and then every 2 seconds thereafter: /*1*/ internal static class TimerDemo /*2*/ { /*3*/ private static Timer s_timer; /*4*/ public static void Main() /*5*/ { /*6*/ Console.WriteLine("Checking status every 2 seconds"); /*7*/ // Create the Timer ensuring that it never fires. This ensures that /*8*/ // s_timer refers to it BEFORE Status is invoked by a thread pool thread /*9*/ s_timer = new Timer(Status, null, Timeout.Infinite, Timeout.Infinite); /*10*/ // Now

WCF with 3.5 and 4.0 together

百般思念 提交于 2019-12-05 06:40:35
Has anyone managed to run wcf successfully in 2.0 integrated mode on IIS7 when .net 4 has been installed? I found that installing .net 4 removed the 2.0 handlers for svc and replaced them with .net 4 versions (this led to a 404.17 error in my v3.5 site), I managed to get my 3.5 site working again by running ServiceModelReg.exe /i from the v3.0 folder (Windows Commuication Foundation) but that removed the 4.0 mappings so they seem to be mutually exclusive? any advise on how to run a 4.0 and 3.5 WCF site on the same IIS7 server? edit There where 4 app pools due to .net 4, classic and integrated

Many to Many mapping not working - EF 4.1 RC

断了今生、忘了曾经 提交于 2019-12-05 06:39:39
问题 UPDATE: After a bit more research it seems a number of my many-to-many mappings aren't working. Hmmm... I'm upgrading a data access project from EF 4.1 CTP4 to EF 4.1 RC and I'm having trouble with the new EntityTypeConfiguration<T> setup. Specifically I'm having an issue with a Many-to-Many relationship. I'm getting a Sequence contains no elements exception when I'm trying to get the .First() item. The particular exception isn't really that interesting. All it's saying is that there are no