ASP.NET Core Middleware not executed

When developing ASP.NET Core applications, if for some reason the breakpoints never hit when the browser tries to refresh or makes requests to the server.

One possible reason is that the responses are cached by the client, this is especially the case with static files. Use Ctrl-F5 in the browser to clear the cache. If the browser uses the data in the cache instead, there won’t be any requests to the server.

This of course applies to any other backend technologies, no requests, no breakpoint hits.

Use custom content-type header in WebAPI or MVC.

The content-type header of the response is affected by the accept header of the request. This is not very obvious at first.

So when you register a custom media type to the JsonFormatter or XmlFormatter, the content-type header will not be changed depending on the type of the response object. Rather it matches the accept header in the request.

If the accept header in the request is not accepted, then the services will default to application/json or application/xml.

Example: let’s say you have a service model called Student, a custom media type “application/mycompany.com+json”, and a web service endpoint that returns a student by ID.

If you just use the browser to make a request to this endpoint, the content-type header in the response will likely be set to “application/json” or “application/xml” depending on your preferred setting and browser.

However if you set the accept header in the request to “application/mycompany.com+json”, the content-type type response header will be set to the same type.

There is no mapping between the types and the service model from the backend side.

Sequence contains no element

When got this error using NHibernate, it’s likely that your mappings and data models are not registered with the NHibernate configuration object.

Simply add the Assembly that contains the mapping files and the model declaration and it will work.

Also, make sure the mapping files are configured to be embedded resource in the project.

FaultException with WCF

One of the reasons why a connection to WCF services cannot be made due to security issue is due to time difference between the client and the server machine.

If you found this issue, synchronizing the time between the client and the server may resolve it.

Hibernate mapping for decimal scale is wrong

When mapping a SQL table to a model using Hibernate or NHibernate, if you configure the mapping like following

<property name=”MyDecCol” type=”Decimal” precision=”28″ scale=”15″>
<column name=”MyDecCol” sql-type=”decimal” not-null=”false” />
</property>

For some reason, Hibernate/NHibernate will treat the field as a decimal with scale = 5 (5 decimal digits on the right side of the decimal separator). So if you save a value to this column with more decimal digits, it will be truncated to only 5 decimal digits.

I’m not sure why, but if you move the attributes to the inner column element, Hibernate and NHibernate will map the values correctly.

<property name=”MyDecCol” type=”Decimal”>
<column name=”MyDecCol” sql-type=”decimal” not-null=”false” precision=”28″ scale=”15″ />
</property>