.net-4.0

Concise way to do a plus equals operation on a Dictionary element that might not be initialized

可紊 提交于 2019-12-10 17:44:50
问题 I'm looking for an extension method or any other suggestion that can help me make this code as concise as possible. foreach( Layer lyr in this.ProgramLayers ) foreach( UWBCEvent evt in this.BcEvents.IncludedEvents ) EventGroupLayerLosses[new EventGroupIDLayerTuple(evt.EventGroupID, lyr)] += GetEL(evt.AsIfs, lyr.LimitInMillions, lyr.AttachmentInMillions); The above code has a fairly clear purpose, I'm bucketing values into groups with a compound key. However, this code will fail because the

System.MethodAccessException, CAS and Visual Studio debugger

十年热恋 提交于 2019-12-10 17:42:40
问题 I am calling ModelMetadataProviders.Current.GetMetadataForProperties to fetch list of ModelMetadata in WPF application with Visual Studio 2010. This call executes fine and I get IEnumerable<> in return. At the code line, where I try to iterate over this, I get System.MethodAccessException. Funny thing is it happens only if I am debugging with F5. If I run code with Ctrl+F5, then I do NOT get this exception and code works fine. If I run exe from windows explorer, it runs fine as well. Surely,

UnobservedTaskException is not killing the process

[亡魂溺海] 提交于 2019-12-10 17:28:58
问题 I am trying to understand the UnobservedTaskException issue in .NET 4.0 so I wrote the folloging code TaskScheduler.UnobservedTaskException += (sender, eventArgs) => Console.WriteLine("unobserved"); Task.Factory.StartNew(() => { throw new Exception(); }, TaskCreationOptions.LongRunning); using (var autoResetEvent = new AutoResetEvent(false)) { autoResetEvent.WaitOne(TimeSpan.FromSeconds(10)); } Console.WriteLine("Collecting"); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(

Loading/Executing CLR 2.0 assemblies in CLR 4.0

こ雲淡風輕ζ 提交于 2019-12-10 17:28:17
问题 Can the CLR 4.0 execute CLR 2.0 IL without the need for source code recompilation? 回答1: Here's a nice article explaining different scenarios. In the comments section there's a link to MSDN which provides further information. 来源: https://stackoverflow.com/questions/2628078/loading-executing-clr-2-0-assemblies-in-clr-4-0

Set combobox display text to a property of ObservableCollection<T>

爱⌒轻易说出口 提交于 2019-12-10 17:24:30
问题 I have the following collection which i would like to bind to a combobox: public ObservableCollection<Parameter> Values { get; set; } public class Parameter { public String Text { get; set; } public String Value { get; set; } } I need to bind the display text of the combobox to the Text property of the Parameter class, I've tried the following ways below but all to no avail: <ComboBox ItemsSource="{Binding Values}" DisplayMemberPath="Parameter.Text" <ComboBox ItemsSource="{Binding Values}"

Make all forms associated with a program come to the front when one form is selected

自古美人都是妖i 提交于 2019-12-10 17:18:47
问题 I have two forms in my application MainForm and HexCompare . If I click off of my app to another window then I click back on one of the two forms only one of them comes to the front. How can I make it so if I click either one of the two forms it will bring both to the top of all open forms in the application? Right now I need to select each form individually to get them to the top of my stack of windows (and this can be very annoying due to the fact that HexCompare has ShowInTaskbar set to

Are we unable to use Interop objects in generic objects in .NET 4.0?

泪湿孤枕 提交于 2019-12-10 17:16:09
问题 I'm working in VS 2010 and working on upgrading our application to .NET 4. The application is built with Excel as the base and we want to take advantage of some of the improvements to .NET for using Excel. But I ran across a strange error that seems to be caused by using an Excel Interop object in a generic dictionary. Here is the error that was generated: C:\MyApp\TheAssembly\MyClass.cs(823,57): error CS1769: Type 'MyApp\OtherAssemply.IMyController.SheetReports' from assembly 'c:\MyApp

Markup extension 'StaticResourceExtension' requires 'IXamlSchemaContextProvider' be implemented in the IServiceProvider for ProvideValue

我们两清 提交于 2019-12-10 17:07:41
问题 A resource extension I've been using for a few years now stopped working at design time in a new .Net 4 project with the following error: Markup extension 'StaticResourceExtension' requires 'IXamlSchemaContextProvider' be implemented in the IServiceProvider for ProvideValue. The relevant method from the extension is the following: public override object ProvideValue(IServiceProvider serviceProvider) { Style resultStyle = new Style(); foreach (string currentResourceKey in resourceKeys) {

Does the .NET Framework 4.0 intaller installs .NET 3.5 as well?

我只是一个虾纸丫 提交于 2019-12-10 16:59:01
问题 .NET 4.0 is meant to run side-by-side with 3.5 and won't run 3.5 apps, which is making me worried about having to instruct my users to download .NET 3.5 instead of just "the latest version". I've read in a blog that the 4.0 installer will install 3.5 as well if it's not already installed but I can't test it right now, did anyone try this or have an answer from a trusted source? 回答1: No, the .NET 4.0 installer will only install version 4. It will run apps targeted to CLR version 2 (like 3.5

Covariance in different FW causes Code Break?

﹥>﹥吖頭↗ 提交于 2019-12-10 16:53:39
问题 I saw Jon Skeet's lecture at the NDC 2010 He mentioned something interesting : public Class Base { public void Foo(IEnumerable<string> strings){} } public Class Child:Base { publc void Foo(IEnumerable<object> objects) {} } Main : List<string> lst = new List<string>(); lst.Add("aaa"); Child c = new Child(); c.Foo(lst); With C# 3 it will call : Base.Foo With C# 4 it will call : Child.Foo I know it's because covariance Question : Isn't it a bit code breaking change ? Is there any workaround so