Questions tagged [.net-4.5]

Version 4.5 of the Microsoft .NET Framework. Use for questions specifically related to .NET Framework 4.5. For questions on .NET Framework generally, use the .net tag.

.net-4.5
Filter by
Sorted by
Tagged with
722 votes
6 answers
587k views

async/await - when to return a Task vs void?

Under what scenarios would one want to use public async Task AsyncMethod(int num) instead of public async void AsyncMethod(int num) The only scenario that I can think of is if you need the task ...
user981225's user avatar
  • 9,032
455 votes
18 answers
1.6m views

How do I make calls to a REST API using C#?

This is the code I have so far: public class Class1 { private const string URL = "https://sub.domain.com/objects.json?api_key=123"; private const string DATA = @"...
NullVoxPopuli's user avatar
421 votes
12 answers
232k views

Do HttpClient and HttpClientHandler have to be disposed between requests?

System.Net.Http.HttpClient and System.Net.Http.HttpClientHandler in .NET Framework 4.5 implement IDisposable (via System.Net.Http.HttpMessageInvoker). The using statement documentation says: As a ...
Fernando Correia's user avatar
377 votes
3 answers
443k views

Do you have to put Task.Run in a method to make it async?

I'm trying to understand async await in the simplest form. I want to create a very simple method that adds two numbers for the sake of this example, granted, it's no processing time at all, it's just ...
Neal's user avatar
  • 9,539
223 votes
5 answers
77k views

Retargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages?

I have migrated a solution that is currently targeting .NET 4.0 in VS2010 to VS2012 and now I would like to re-target it to .Net 4.5 What I am not sure about is the NuGet packages. For example EF5, ...
Ivan Zlatev's user avatar
  • 13.1k
221 votes
6 answers
98k views

What's the difference between Task.Start/Wait and Async/Await?

I may be missing something but what is the difference between doing: public void MyMethod() { Task t = Task.Factory.StartNew(DoSomethingThatTakesTime); t.Wait(); UpdateLabelToSayItsComplete(); }...
Jon's user avatar
  • 39.5k
212 votes
4 answers
163k views

Using 'async' in a console application in C# [duplicate]

I have this simple code: public static async Task<int> SumTwoOperationsAsync() { var firstTask = GetOperationOneAsync(); var secondTask = GetOperationTwoAsync(); return await ...
Royi Namir's user avatar
  • 147k
209 votes
11 answers
111k views

Is it possible to await an event instead of another async method?

In my C#/XAML metro app, there's a button which kicks off a long-running process. So, as recommended, I'm using async/await to make sure the UI thread doesn't get blocked: private async void ...
Max's user avatar
  • 9,577
200 votes
10 answers
337k views

C# HttpClient 4.5 multipart/form-data upload

Does anyone know how to use the HttpClient in .Net 4.5 with multipart/form-data upload? I couldn't find any examples on the internet.
ident's user avatar
  • 3,935
198 votes
2 answers
9k views

Why would finding a type's initializer throw a NullReferenceException?

This has got me stumped. I was trying to optimize some tests for Noda Time, where we have some type initializer checking. I thought I'd find out whether a type has a type initializer (static ...
Jon Skeet's user avatar
  • 1.5m
190 votes
5 answers
119k views

Async/await vs BackgroundWorker

In the past few days I have tested the new features of .net 4.5 and c# 5. I like its new async/await features. Earlier I had used BackgroundWorker to handle longer processes in the background with ...
Tom's user avatar
  • 3,999
190 votes
4 answers
225k views

How to cancel a Task in await?

I'm playing with these Windows 8 WinRT tasks, and I'm trying to cancel a task using the method below, and it works to some point. The CancelNotification method DOES get called, which makes you think ...
Carlo's user avatar
  • 25.8k
184 votes
19 answers
92k views

Cleaner way to do a null check in C#? [duplicate]

Suppose, I have this interface, interface IContact { IAddress address { get; set; } } interface IAddress { string city { get; set; } } class Person : IPerson { public IContact contact { ...
now he who must not be named.'s user avatar
184 votes
1 answer
6k views

Catch-22 prevents streamed TCP WCF service securable by WIF; ruining my Christmas, mental health

I have a requirement to secure a streamed WCF net.tcp service endpoint using WIF. It should authenticate incoming calls against our token server. The service is streamed because it is designed to ...
user avatar
171 votes
6 answers
223k views

Targeting .NET Framework 4.5 via Visual Studio 2010

Today I installed the .NET Framework 4.5 on my machine expecting to be able to use it from Visual Studio 2010, since it's just a minor update that should't pose problems for Visual Studio ...
Golvellius's user avatar
  • 1,928
155 votes
2 answers
168k views

How does Task<int> become an int?

We have this method: async Task<int> AccessTheWebAsync() { HttpClient client = new HttpClient(); Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com"); ...
Freeman's user avatar
  • 5,741
154 votes
6 answers
350k views

Where is the .NET Framework 4.5 directory?

I've installed Windows 8, Visual Studio 2012 but don't have a v4.5 directory in %WINDIR%\Microsoft.NET\Framework. Have I done something wrong, or is .NET 4.5 different from others? If it's because I ...
Nick Randell's user avatar
149 votes
6 answers
199k views

Run two async tasks in parallel and collect results in .NET 4.5

I've been trying for a while to get something I thought would be simple working with .NET 4.5 I want to fire off two long running tasks at same time and collect the results in in the best C# 4.5 (...
Simon_Weaver's user avatar
132 votes
3 answers
48k views

Is async HttpClient from .Net 4.5 a bad choice for intensive load applications?

I recently created a simple application for testing the HTTP call throughput that can be generated in an asynchronous manner vs a classical multithreaded approach. The application is a able to ...
Florin Dumitrescu's user avatar
124 votes
2 answers
85k views

How to select .NET 4.5.2 as a target framework in Visual Studio

I have installed .NET Framework 4.5.2 on Windows 8.1. But in Visual Studio 2013 I do not see the .NET Framework 4.5.2 option (see screenshot). How do I target my project for .NET 4.5.2?
IT Hit WebDAV's user avatar
115 votes
29 answers
263k views

The type or namespace name 'System' could not be found

I have the following errors (and more) in all my views (*.cshtml) when opening my project in Visual Studio 2015 Professional. Error CS0246 The type or namespace name 'System' could not be found (...
Hélder Gonçalves's user avatar
112 votes
2 answers
113k views

HttpClient.GetAsync with network credentials

I'm currently using HttpWebRequest to get a website. I'd like to use the await pattern, which is not given for HttpWebRequests. I found the class HttpClient, which seems to be the new Http worker ...
Jan K.'s user avatar
  • 2,582
104 votes
15 answers
55k views

Can Visual Studio 2012 be installed side-by-side w/ Visual Studio 2010?

Will Visual Studio 2012 interfere/break .NET 4 and/or Visual Studio 2010 if installed side-by-side on the same instance of Windows?
Chris Pietschmann's user avatar
103 votes
3 answers
83k views

Proper way to implement a never ending task. (Timers vs Task)

So, my app needs to perform an action almost continuously (with a pause of 10 seconds or so between each run) for as long as the app is running or a cancellation is requested. The work it needs to do ...
Josh's user avatar
  • 2,103
100 votes
1 answer
90k views

Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

I am working with .NET4.5 and VS2013, I have this query that gets dynamic result from db. dynamic topAgents = this._dataContext.Sql( "select t.create_user_id as \"User\", sum(t.netamount) as \"...
Matas Vaitkevicius's user avatar
91 votes
2 answers
47k views

What does the Microsoft.Bcl.Build NuGet package do?

I'm unable to find any documentation on this - the links from the Microsoft.Bcl.Build Nuget page don't provide much help: This package provides build infrastructure components so that projects ...
crimbo's user avatar
  • 10.8k
88 votes
6 answers
138k views

Is it possible to run a .NET 4.5 app on XP?

First, I have read the following: Connect case VS case and especially this channel9 post So, from the last bullet, I really think there is no way around this, but I had to see if I could get a ...
Justin Pihony's user avatar
87 votes
13 answers
137k views

How to 'await' raising an EventHandler event

Sometimes the event pattern is used to raise events in MVVM applications by or a child viewmodel to send a message to its parent viewmodel in a loosely coupled way like this. Parent ViewModel ...
Simon_Weaver's user avatar
87 votes
5 answers
182k views

Differences between .NET 4.0 and .NET 4.5 in High level in .NET

Eager to know Differences between .NET 4.0 and .NET 4.5 in High level in .NET and also differences in ASP.NET, C# also in these frameworks
venkat's user avatar
  • 5,678
86 votes
9 answers
39k views

How can I create a new instance of ImmutableDictionary?

I would like to write something like this: var d = new ImmutableDictionary<string, int> { { "a", 1 }, { "b", 2 } }; (using ImmutableDictionary from System.Collections.Immutable). It seems like ...
Lukáš Lánský's user avatar
85 votes
4 answers
39k views

What's the difference between InvokeAsync and BeginInvoke for WPF Dispatcher

I noticed in .NET 4.5 that the WPF Dispatcher had gotten a new set of methods to execute stuff on the Dispatcher's thread called InvokeAsync. Before, .NET 4.5 we had Invoke and BeginInvoke which ...
Isak Savo's user avatar
  • 35.5k
82 votes
3 answers
142k views

Which versions of SSL/TLS does System.Net.WebRequest support?

Now that SSL 3 has been found to be vulnerable to the POODLE attack: Which versions of SSL/TLS does System.Net.WebRequest use when connecting to any https Uri? I use WebRequest to connect to ...
JK.'s user avatar
  • 21.6k
79 votes
1 answer
148k views

Await operator can only be used within an Async method [duplicate]

I'm trying to make a simple program to test the new .NET async functionality within Visual Studio 2012. I generally use BackgroundWorkers to run time-consuming code asynchronously, but sometimes it ...
William Thomas's user avatar
75 votes
4 answers
41k views

HTTP HEAD request with HttpClient in .NET 4.5 and C#

Is it possible to create a HTTP HEAD request with the new HttpClient in .NET 4.5? The only methods I can find are GetAsync, DeleteAsync, PutAsync and PostAsync. I know that the HttpWebRequest-class is ...
The Wavelength's user avatar
72 votes
4 answers
34k views

OWIN HttpListener not located

When I try to start : WebApp.Start<SrvcHst>(new StartOptions { Port = 9956, ServerFactory = "Microsoft.Owin.Host.HttpListener" }); I get the following exception. What could be the root ...
GilliVilla's user avatar
  • 5,018
72 votes
3 answers
73k views

Create zip file from byte[]

I am trying to create a Zip file in .NET 4.5 (System.IO.Compression) from a series of byte arrays. As an example, from an API I am using I end up with a List<Attachment> and each Attachment has ...
Justin Helgerson's user avatar
69 votes
2 answers
45k views

Does C# 7.0 work for .NET 4.5?

I created a project in Visual Studio 2017 RC to check whether I can use new C# 7.0 language features in a .NET Framework 4.5 project. It seems to me that after referencing System.ValueTuple NuGet, new ...
Lukáš Lánský's user avatar
69 votes
6 answers
11k views

Why doesn't generic ICollection implement IReadOnlyCollection in .NET 4.5?

In .NET 4.5 / C# 5, IReadOnlyCollection<T> is declared with a Count property: public interface IReadOnlyCollection<out T> : IEnumerable<T>, IEnumerable { int Count { get; } } I ...
Zaid Masud's user avatar
  • 13.3k
67 votes
4 answers
15k views

WPF Programming Methodology

In my APP I'm using an API of a software that my tool is managing. I've DAL that contain 16 classes, 3 of them are singletons. I've some logic in the .cs files and XAML's off course. My question is, ...
SigmaOmega's user avatar
66 votes
10 answers
120k views

Is that possible to send HttpWebRequest using TLS1.2 on .NET 4.0 framework

My application connects to Experian server and Experian will soon stop supporting TLS 1.0 and TLS 1.1. All connectivity using HTTPS must use TLS Version 1.2. I want to do some research on that issue ...
gene's user avatar
  • 2,098
65 votes
7 answers
28k views

TemporaryGeneratedFile_[guid] in /obj/debug breaking build

I have 3 temporary files being created in obj/debug: E.g. TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs ...
NikolaiDante's user avatar
  • 18.6k
63 votes
1 answer
26k views

What can I do in C# 5 with .Net 4.5 that I couldn't do in C# 4 with .Net 4? [closed]

I have Visual Studio 2012 RC installed on Windows 8 Release Preview and my question is are there any useful new features not related to Metro, or is Metro what seperates .Net 4 and .Net 4.5?
JMK's user avatar
  • 27.7k
62 votes
7 answers
47k views

How do I detect at runtime that .NET version 4.5 is currently running your code?

I installed .NET 4.5 Developer preview from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27541, which 'replaces' .NET 4.0 version. However, the old way to detect the .NET ...
Evereq's user avatar
  • 1,671
61 votes
4 answers
34k views

What are the differences between using ConfigureAwait(false) and Task.Run?

I understand that it's recommended to use ConfigureAwait(false) for awaits in library code so that subsequent code does not run in the caller's execution context, which could be a UI thread. I also ...
Sam's user avatar
  • 41.5k
57 votes
10 answers
56k views

awaitable Task based queue

I'm wondering if there exists an implementation/wrapper for ConcurrentQueue, similar to BlockingCollection where taking from the collection does not block, but is instead asynchronous and will cause ...
spender's user avatar
  • 119k
56 votes
1 answer
3k views

Unit-Test project fails to build after installing .NET 4.5

I have a WPF solution in .NET 4.0 that includes a Unit Test project which tests the different commands used in the ViewModels. Everything was working fine, but then I installed .NET 4.5 and VS2012. ...
atiyar's user avatar
  • 8,042
54 votes
5 answers
65k views

How to reliably detect the actual .NET 4.5 version installed?

My actual problem is that I have encountered two versions of .NET 4.5 full setups: a (possibly) older one, which is also available when downloading SQL Server Data Tools size: 50,349,920 md5: ...
alexandrul's user avatar
54 votes
3 answers
59k views

Using a proxy with .NET 4.5 HttpClient

I'm troubleshooting a bug with a service I call through .NET's HttpClient, trying to route the request through a local proxy (Fiddler), but my proxy settings seem to not be taking effect. Here's how ...
Mike Ruhlin's user avatar
  • 3,546
53 votes
1 answer
44k views

Non-static method requires a target. Entity Framework 5 Code First

I am getting the error "Non-static method requires a target." when I run the following query: var allPartners = DbContext.User .Include(u => u.Businesses) ...
ilivewithian's user avatar
  • 19.6k
53 votes
4 answers
66k views

IList<T> and IReadOnlyList<T>

If I have a method that requires a parameter that, Has a Count property Has an integer indexer (get-only) What should the type of this parameter be? I would choose IList<T> before .NET 4.5 ...
Şafak Gür's user avatar
  • 7,185

1
2 3 4 5
79