.net-4.5

Implementing read-only properties with { get; }

我们两清 提交于 2019-12-08 22:29:13
问题 Why doesn't this run: class Program { static void Main(string[] args) { Apple a = new Apple("green"); } } class Apple { public string Colour{ get; } public Apple(string colour) { this.Colour = colour; } } 回答1: Your code is valid for C# 6, which comes with Visual Studio 2015. It is not valid for previous versions of the language or Visual Studio. Technically, you can install an old pre-release version of Roslyn in VS 2013 but it isn't worth the trouble now that VS 2015 was released. For this

Is it possible to select an Action with AttributeRouting in .NET MVC based on the Media Type of the Accept header?

天大地大妈咪最大 提交于 2019-12-08 19:34:16
问题 I want to select an Action of my Controller based on the Media Type requested in the Accept header. For example, I have a resource called a subject. Its assigned route is: GET /subjects/{subjectId:int} Normally, the browser is requesting text/html , which is fine. The default Media Formatter handles this great. Now, I have custom logic I want to perform when this same route is accessed with an accept header specifying application/pdf as the accepted Media Type. I could create a custom Media

SQLite.NET - System.NotSupportedException: Cannot compile: Parameter

青春壹個敷衍的年華 提交于 2019-12-08 18:06:43
问题 I am using SQLite.NET Async (http://www.nuget.org/packages/SQLite.Net.Async-PCL/) in a Xamarin iOS project, but I am having a problem using the table predicate queries. Anytime I use the Get method below, which is very simple, I receive an exception that the expression could not be compiled, System.NotSupportedException: Cannot compile: Parameter. However, if I use a low level query, as with the GetQuery method, it works fine. Is there something I am doing wrong in the definition of my table

Thread.CurrentPrincipal is authenticated but ClaimsPrincipal.Current is not

时光毁灭记忆、已成空白 提交于 2019-12-08 17:58:34
问题 I'm using Claims based Authorization in my WebApi project and have a method where I check if the current Identity is authenticated. When I use ClaimsPrincipal.Current the current Identity is not authenticated but when I use Thread.CurrentPrincipal it is. ClaimsPrincipal.Current.Identity.IsAuthenticated; //False Thread.CurrentPrincipal.Identity.IsAuthenticated; //True This seems strange especially since the MSDN says ClaimsPrincipal.Current just returns Thread.CurrentPrincipal: Remarks By

.NET 4.5 MethodInfo serialization breaking change

℡╲_俬逩灬. 提交于 2019-12-08 16:49:08
问题 The problem An object (with a private MethodInfo field) serialized with version 1.0 of an assembly won't be deserialized with the version 1.1 of that assembly (a SerializationException will be thrown because required method has not been found). What's changed? I found that in .NET 4.5 the serialization mechanism of a MemberInfo via MemberInfoSerializationHolder has been changed. In the past (up to .NET 4.0) the serialized data was the method signature (obtained with a simple MethodInfo

File creation time in C#

◇◆丶佛笑我妖孽 提交于 2019-12-08 16:35:47
问题 I need to get when a file was created - I have tried using: FileInfo fi = new FileInfo(FilePath); var creationTime = fi.CreationTimeUtc; and var creationTime = File.GetCreationTimeUtc(FilePath); Both methods generally return the wrong creation time - I guess it is being cached somewhere. The file is deleted and re-created with the same name and I need to know when/if it has been re-created (by checking if the created date/time has changed) - I had planned to do this by seeing it the file

Why cant a .net 4.0 project reference a 4.5 assembly?

送分小仙女□ 提交于 2019-12-08 15:13:28
问题 I am working on a project targeting .NET 4.0 and now I need to reference a third party dll which was built targeting .NET 4.5. It seems that visual studio does not accept that? Why? VS shows me that dll name does not exist in current context. 回答1: Because you are referencing to the higher version. Microsoft can be backcompatible, but not "future compatible". You need to convert your entire project to higher vesion, in order to be able to use that binary. Don't know what tecnology you are

Where is the .NET Framework 4.5 directory?

泪湿孤枕 提交于 2019-12-08 14:52:21
问题 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 have not installed the tools, is there a set of different tools to download? As far as I can tell, I am able to build .NET 4.5 apps OK. 回答1: .NET 4.5 is an in place replacement for 4.0 - you will find the assemblies in the 4.0 directory. See the blogs by Rick Strahl and Scott Hanselman on this

How to chain a task to a previous instance of it?

寵の児 提交于 2019-12-08 14:48:38
问题 Looking to chain a task to a previous instance if it exists. Currently, both are executed at the same time. Initial code that works for one task : private async void MenuMediaAddFiles_OnClick(object sender, RoutedEventArgs e) { var dialog = GetDefaultOpenFileDialog(); using (dialog) { if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (var progress = new SimpleProgress(this)) { int addFiles = await _context.AddFiles(dialog.FileNames, progress); Console.WriteLine("Files

After installing .NET 4.5, previous Unit-Test project fails to build

不打扰是莪最后的温柔 提交于 2019-12-08 14:36:08
问题 I have a .NET 4.0 WPF solution that includes a Unit Test project which tests the different commands used in the viewmodels. Everything was fine. Then I installed .NET framework 4.5 and then VS2012, and started getting error messages like - XYZProject.UsersViewModel_Accessor.AddUserToAccountsCommand' is not supported by the language Before installing VS2012 the UnitTestFramework.dll was referenced from - C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\ which was