Dotnet
- Web Api 2, OWIN and StructureMap
Add the following code to your startup file: public class Startup { public void Configuration(IAppBuilder app) { // setup http configuration GlobalConfiguration.Configure(config => { //configure dependency injection var container = IoC.Initialize(); config.ConfigureDependencyInjection(container); config.ConfigureControllerSelector(); } } } And create the following IoC container: public static class IoC { public static IContainer Initialize() { var container = new Container(c => { c.AddRegistry(); // TODO: Add custom registry here }); return container; } } And a WebApi Registry:
- IDX10708: 'System.IdentityModel.Tokens.JwtSecurityTokenHandler' cannot read this string: 'Bearer'.
Today I got the following message when trying to send the rawData of a JwtSecurityToken I had created manually: IDX10708: ‘System.IdentityModel.Tokens.JwtSecurityTokenHandler’ cannot read this string: ‘Bearer’. The problem was that the rawData portion of the JwtSecurityToken is not populated until the token has been validated. I ended up using the following solution to create and validate JWT Tokens.
- Nuget Push failed to process request System.Net.HttpWebRequest.GetResponse()
When trying to push a NuGet package to our new local NuGet repository we recieved the following error: System.InvalidOperationException: Failed to process request. ‘Internal Server Er ror’. The remote server returned an error: (500) Internal Server Error.. —> System.N et.WebException: The remote server returned an error: (500) Internal Server Erro r. at System.Net.HttpWebRequest.GetResponse() at NuGet.RequestHelper.GetResponse(Func`1 createRequest, Action`1 prepareRequ est, IProxyCache proxyCache, ICredentialCache credentialCache, ICredentialProvid er credentialProvider) at NuGet.HttpClient.GetResponse() at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable`1 expectedStatusCode) — End of inner exception stack trace — at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable`1 expectedStatusCode) at NuGet.PackageServer.PushPackageToServer(String apiKey, Func`1 packageStrea mFactory, Int32 timeout) at NuGet.PackageServer.PushPackage(String apiKey, IPackage package, Int32 tim eout) at NuGet.Commands.PushCommand.PushPackageCore(String source, String apiKey, P ackageServer packageServer, String packageToPush, TimeSpan timeout) at NuGet.Commands.PushCommand.PushPackage(String packagePath, String source, String apiKey, TimeSpan timeout) at NuGet.Commands.PushCommand.ExecuteCommand() at NuGet.Commands.Command.Execute() at NuGet.Program.Main(String args)
- Disabling Roslyn Compiler Preview Not Working
After installing the Roslyn preview we found that when switching back to the standard compiler by going to tools | extensions and updates | Roslyn Preview | Disable was being ignored. In order for disable to work properly you need to delete the following target files created by the Roslyn Preview:
- Invalid token '=' in class, struct, or interface member declaration { get; } =
If you are getting errors like: Invalid token ‘=’ in class, struct, or interface member declaration when you compile your code in Visual Studio and the class looks something like: public class Point(int x, int y) { public int X { get; } = x; public int Y { get; } = y; } then you will need to install the new Roslyn compiler from Microsoft. The error you are getting is because the new compiler has many new language features that are not compatible with the previous compiler. The above code is an example of the new Primary Constructors feature
- Visual Studio warning: “Some of the properties associated with the solution could not be read”
Today I received the message: One or more projects in the solution were not loaded correctly. Please see the Output Window for details when opening a solution in Visual Studio. Unfortunatley the details in the output window were not very helpful:
- .NET MVC Windows Authentication
Turns out it is quite easy to allow your users to log on with their Active Directory usernames and passwords when you expose a .NET MVC application to the internet. Either select the following option from the new project menu:
- No EditorOptionDefinition export found for the given option name
I received the following message in Visual Studio 2013 when trying to open a c sharp file: ————————— Microsoft Visual Studio ————————— No EditorOptionDefinition export found for the given option name: TextViewHost/LineNumberMargin Parameter name: optionId ————————— OK —————————
- OData Web Api Date Filter 'Edm.DateTime' and 'Edm.String' incompatible types
I was getting the following error when trying to filter an odata source by date: { "Message":"The query specified in the URI is not valid.", "ExceptionMessage":"A binary operator with incompatible types was detected. Found operand types 'Edm.DateTime' and 'Edm.String' for operator kind 'GreaterThan'.", "ExceptionType":"Microsoft.Data.OData.ODataException", "StackTrace":" at Microsoft.Data.OData.Query.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right) at Microsoft.Data.OData.Query.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorQueryToken binaryOperatorToken) at Microsoft.Data.OData.Query.MetadataBinder.BindBinaryOperator(BinaryOperatorQueryToken binaryOperatorToken) at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token) at Microsoft.Data.OData.Query.FilterBinder.BindFilter(CollectionNode path, QueryToken filter) at Microsoft.Data.OData.Query.ODataUriParser.ParseFilter(String filter, IEdmModel model, IEdmType elementType, IEdmEntitySet entitySet) at System.Web.Http.OData.Query.FilterQueryOption.get_FilterClause() at System.Web.Http.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings) at System.Web.Http.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings) at System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings) at System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings) at System.Web.Http.QueryableAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions) at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpActionDescriptor actionDescriptor) at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"} I was using the following URI:
- Kendo MVC Grid Filter Expected primaryExpression
If you receive the error: Expected primaryExpression when trying to add a filter to the Kendo MVC grid then you have probably formatted it incorrectly. Try this: .DataSource(dataSource => dataSource .Ajax() .Filter(filters => filters.Add(trip => trip.DepartureDate).IsGreaterThanOrEqualTo(DateTime.Now.Date).And().IsLessThan(DateTime.Now.Date.AddDays(1))) .Model(model => model.Id(p => p.ID)) .Read(read => read.Action("GetTrips", "Trip")) )