.net-4.0

Cross-thread operation not valid, even if using InvokeRequired [duplicate]

我只是一个虾纸丫 提交于 2019-12-08 20:45:45
问题 This question already has answers here : Invoke or BeginInvoke cannot be called on a control until the window handle has been created (10 answers) Closed 12 months ago . I have a form with my custom controls on it. I have a method in my Form: private void SetEnabledOnControls(bool val) { if (InvokeRequired) { Invoke((Action<bool>)SetEnabledOnControls, val); } else { //do the work - iterate over child controls, //and they iterate over their children, etc... } } And inside the methods that are

|DataDirectory| returns wrong path to AppData folder

馋奶兔 提交于 2019-12-08 20:41:38
问题 |DataDirectory|, you had one job. |DataDirectory| on IIS7.5 resolves to: C:\inetpub\wwwroot\appname\App_Data That folder does not exist. The correct folder is: C:\inetpub\wwwroot\appname\bin\App_Data All is well on the dev machine, but when I deploy to the server, AppData is placed within bin\ . I use AppData as shown in any Visual Studio 2010 project and deploy with " Build Deployment Package " (VS2010) then " Import Application " (IIS Manager). I know I can set the path manually with

Static constructor called twice for PerSession WCF service

大兔子大兔子 提交于 2019-12-08 19:55:21
问题 Can't udnerstand why type constructor for PerSession / WCF service was calling twice. ConcurrencyMode is Multiple . Just launching five simultaneous clients which do the same WCF service method call, in a log I see that static constructor was called twice, the first time and after 3 seconds second time with an other ProcessId/ThreadId . No exceptions neither in constructor itself nor WCF trace logs. Constructor execution time is ~10 milliseconds as per log. This results in all static fields

DataContext compiled query problem with .NET 4

核能气质少年 提交于 2019-12-08 19:48:01
问题 My project (UI layer is asp.mvc) was developed using .NET 3.5. After upgrading to .NET 4.0 I have got problem with compiled queries: [ArgumentException: Query was compiled for a different mapping source than the one associated with the specified DataContext.] System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext context, Object[] args) +863348 System.Data.Linq.CompiledQuery.Invoke(TArg0 arg0, TArg1 arg1) +110 Every time when I run my query I am passing my context return StaticQueries

Calling 'IsAssignableFrom' from an interface doesn't return the concrete class

孤街醉人 提交于 2019-12-08 19:26:54
问题 I am trying to return the object type of the class that implements the interface defined in the code below. The linq statement only returns the interface itself, and so the console output is just: AssignableExperiment.IRule Why isn't the concrete class being returned? using System; using System.Linq; namespace AssignableExperiment { public interface IRule { void Validate(string s); } public class ConcreteRule : IRule { public void Validate(string s) { // some logic } } class Program { static

Reflection to invoke the constructor with ConstructorInfo

别说谁变了你拦得住时间么 提交于 2019-12-08 18:04:36
问题 In a very Simple class like below, class Program { public Program(int a, int b, int c) { Console.WriteLine(a); Console.WriteLine(b); Console.WriteLine(c); } } and I use reflection to invoke the constructor something like this... var constructorInfo = typeof(Program).GetConstructor(new[] { typeof(int), typeof(int), typeof(int) }); object[] lobject = new object[] { }; int one = 1; int two = 2; int three = 3; lobject[0] = one; lobject[1] = two; lobject[2] = three; if (constructorInfo != null) {

msbuild ASPNETCOMPILER ASPNETRUNTIME startIndex error

ぃ、小莉子 提交于 2019-12-08 17:41:52
问题 I have a web project that builds fine on Windows 7 with no error. When I upgraded to Windows 8, compiling the project into a compiled website throws an error. Compiling from the csproj file (not creating a website) works fine. This is the actual error that is thrown by msbuild ASPNETCOMPILER : error ASPRUNTIME: startIndex cannot be larger than length of string. [mycsproj.file.here] The line that msbuild is running that is throwing the error is C:\Windows\Microsoft.NET\Framework\v4.0.30319

In .Net 4.0, can DirectorySearch return LDAP results in a way that allows me to page through them?

半腔热情 提交于 2019-12-08 17:32:24
问题 I am working in C#, and am trying to use DirectorySearch to query the groups of an extremely large Microsoft ActiveDirectory LDAP server. So, in my application, I'm going to have a paged list of groups, with searching capability. Naturally, I don't want to hammer my LDAP server with passing me the entire result set for these queries every time I hit "Next Page". Is there a way, using DirectorySearch, to retrieve ONLY a single arbitrary page's results, rather than returning the entire result

Under what context am I running in C#?

Deadly 提交于 2019-12-08 17:12:29
问题 I was wondering... When I have a code like this: lock (obj) { MyCode.MyAgent(); } Can MyAgent contain code that recognizes it is running under a lock block? What about: for (int i=0;i<5;i++) { MyCode.MyAgent(); } Can MyAgent contain code that recognizes it is running under a loop block ? The same question can be asked for using blocks, unsafe code , etc... - well you get the idea... Is this possible in C#? This is just a theoretical question, I'm not trying to achieve anything... just

Can a class property/field be of anonymous type in C# 4.0?

醉酒当歌 提交于 2019-12-08 16:31:46
问题 As in: public class MyClass { private static var MyProp = new {item1 = "a", item2 = "b"}; } Note: The above doesn't compile nor work (the var cannot be used there), it's only to show my point. Update : Just to clarify the question, I had already tried using private static dynamic MyProp = new {item1 = "a", item2 = "b"}; and this works, but it doesn't generate intellisense because of the dynamic typing. I am aware that anonymous typing is just a compiler trick, so I hoped I could use this