.net-4.0

RuntimeBinderException - C# .NET 4 Dynamic Keyword - Help Me Understand Why Method Isn't Matching

风流意气都作罢 提交于 2019-12-10 22:02:06
问题 I've built a generic config system for an HttpModule that allows pluggable HTTP header inspectors. For reference, here is the basic layout of the code -- this should be enough to get a feel for what I'm doing: public interface IHttpHeaderInspectingAuthenticatorFactory<T> where T: HttpHeaderInspectingAuthenticatorConfigurationElement { IHttpHeaderInspectingAuthenticator<T> Construct(T config); } public class BasicAuthenticationInspectingAuthenticatorFactory : IHttpHeaderInspectingAuthenticator

A call to PInvoke has unbalanced the stack… dll import fails even with Cdecl

孤街醉人 提交于 2019-12-10 21:30:48
问题 Aha, this question is all over stack overflow so I've already proceeded to add CallingConvention = CallingConvention.Cdecl which has worked just fine for other libraries I've had to import but in this case, nothing changes and it still fails with the same error message. The original code for this came out of a .net 3.5 project and works perfectly fine: [DllImport("Compiled DSP.dll")] private static extern int fnGetConfigParam(int nID, ref stParamInt pstParam); [DllImport("Compiled DSP.dll")]

WCF: Wrong URI being returned by OperationContext.IncomingMessageProperties.Via

送分小仙女□ 提交于 2019-12-10 21:24:12
问题 I am hosting WCF services in IIS. I have multiple hostname bindings set up in IIS for the site. However, when making requests to any of the non-default bindings, the correct url doesn't get reported by the OperationContext.IncomingMessageProperties.Via property. The URL that gets reported uses the default binding's hostname as the base, with same path and querystring. For example, assuming the following bindings: http://subfoo.services.myapp.com (first/default entry) http://subbar.services

Converting anonymous type to DataTable

▼魔方 西西 提交于 2019-12-10 21:14:07
问题 What is the fastest way to convert anonymous type to DataTable? Update: I want to get and populate DataTable from anonymous type. If reflection is neccesary, how can I to do it using reflection? 回答1: Found here: var result = from p in dataSource group p by p.City into cities select new { Property1 = cities.Key, Property 2= cities.Average(p => p.Age) }; dt.Columns.Add("Property1"); dt.Columns.Add("Property2"); foreach (var item in result) { dt.Rows.Add(item.Property1,item.Property2); } See

Using .NET 4.0 Task in ASP.NET

元气小坏坏 提交于 2019-12-10 21:04:45
问题 Are there any caveats or short comings to using the new Task API in System.Threading.Task in ASP.NET hosted under IIS? I know prior to .NET 4.0 working with any of the ThreadPool actions inside of IIS was always recommended to be avoided. 回答1: Any caveats to using ThreadPool with IIS would still be valid using System.Threading.Task , as the Task API is just an additional layer of abstraction over System.Threading . For long-running tasks in the background, I use a ThreadPool inside a Windows

Get Types defined in an assembly only [duplicate]

喜欢而已 提交于 2019-12-10 20:49:49
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes() I would like to get all the types in an assembly. However, I get the following error: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. The problem is the assembly I am getting the types from is referencing another assembly that is only available in the production environment, and not

WCF custom binding for compression

若如初见. 提交于 2019-12-10 20:33:39
问题 Following the sample for compression by Microsoft. I have added the encoder, encoder factory, and binding element to my solution. The difference from their sample is that we do not register our endpoints via the config file (requirement), but instead use a custom Service Host Factory. Service Host: protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses); if (host.Description.Endpoints.Count

Storing 2-dimensional ints as Readonly/const in separate class whilst keeping non-exposed

孤街醉人 提交于 2019-12-10 20:16:00
问题 This is my first question after having used this place as my "go to" for a general opinion on what works/doesn't/why and the such. So let's try this out... With my limited experience I've been trying to get my head round the better ways of creating fixed data fields that I can refer back to throughout my program - things like end-user-viewable strings that I show repeatedly and other parameters that I'd like to keep constant and safe from change. I've kept my reused data in separate static

Convert double for-loop into a linq query

这一生的挚爱 提交于 2019-12-10 20:13:34
问题 I have a loop which, once simplified, looks like this: Dictionary<Tuple<A,G>,Decimal> results = new Dictionary<Tuple<A,G>,Decimal>(); foreach( A a in collectionA ) foreach( B b in collectionB ) results [Tuple.Create(a, (G)b.groupBy)] += (Decimal) Func(a, b); Is there a way I can replicate this result using a Linq query (with GroupBy , Sum and ToDictionary for example)? (as suggested in this answer to a previous question: Concise way to do a plus equals operation on a Dictionary element that

Targeting .NET3.5 with ASP.NET MVC2 Web Application in Visual Studio 2010?

纵饮孤独 提交于 2019-12-10 19:55:50
问题 Our current environment is .NET 3.5 SP1 but we're in the process of migrating to .NET4 and Visual Studio 2010. I would like to stick to using .NET 3.5 for the deployment/production environment however use Visual Studio and TFS 2010 for development, until the production environment is cleared for upgrade to .NET4. Is this possible (I assume yes :B), and how? What I have tried is changing the TargetFrameworkVersion in the project settings to "v3.5". However, I get a build failure due to the