I have an MVC 3 application that works fine when running locally from visual studio,
There are two bat files that pre compile the application ready for deployment, when i run the bat files and upload the deployment folder to the web server a load of errors are thrown including a null exception error,
The error can be seen by visiting the following URL, i can also provide the full stack trace on a document if required, i didnt want to post it here as its so big.
error can be seen here
I cant understand where the error is coming from as everything works locally, t seems these errors are being created when the bat files are compiling the application, has anyone had similar experiences after deploying an MVC app? can anyone offer any advice on what may be causing the problem?
Thanks
Liam
UPDATE=============
This is the GetTax method, this code has been thoroughly tested as its part of NopCommerce 2.2, the errors only occur after the solution is compiled via the BAT files which is again standard for building a nop commerce 2.2 app, am i right in thinking its got to be something on my machine that is causing these problems when the BAT files are ran and the code is compiled for deployment?
public virtual decimal GetTaxRate(ProductVariant productVariant, int taxCategoryId,
Customer customer)
{
//tax exempt
if (IsTaxExempt(productVariant, customer))
{
return decimal.Zero;
}
//tax request
var calculateTaxRequest = CreateCalculateTaxRequest(productVariant, taxCategoryId, customer);
//make EU VAT exempt validation (the European Union Value Added Tax)
if (_taxSettings.EuVatEnabled)
{
if (IsVatExempt(calculateTaxRequest.Address, calculateTaxRequest.Customer))
{
//return zero if VAT is not chargeable
return decimal.Zero;
}
}
//active tax provider
var activeTaxProvider = LoadActiveTaxProvider();
//get tax rate
var calculateTaxResult = activeTaxProvider.GetTaxRate(calculateTaxRequest);
if (calculateTaxResult.Success)
return calculateTaxResult.TaxRate;
else
return decimal.Zero;
}
The stack trace indicates that it's coming from the method GetTaxRate in TaxService.cs. I'm guessing this isn't anything ASP.NET MVC specific, but a deployment issue. It could be database permissions or connection strings.. you'll have to check what that method is doing.
Nop.Services.Tax.TaxService.GetTaxRate(ProductVariant productVariant, Int32 taxCategoryId, Customer customer) in c:\Nop 2.2 Source\just4fashion2.2source\Libraries\Nop.Services\Tax\TaxService.cs:240
It probably has something do with a configuration mismatch between your development and production environment.
If you look at the top of the stack trace you see that is has probably nothing to do with MVC but with someting in your TaxService.
[NullReferenceException: Object reference not set to an instance of an object.]
Nop.Services.Tax.TaxService.GetTaxRate(ProductVariant productVariant, Int32 taxCategoryId, Customer customer) in c:\Nop 2.2 Source\just4fashion2.2source\Libraries\Nop.Services\Tax\TaxService.cs:240
You need to check on which element the Null exception occurs.
Things to check:
Is productVariant null?
Is customer null?
Are there any other elements accessed in this function like a Repository or Factory that could be null?
Are there any configuration changes between local and production like connectionstring, logging or security settings?
Related
Environment
.NET Core 5 Web Application
IIS 10
Azure VM
Issue
Executing a GET action results in that action being called a second time. The first call shows cookie information. The second does not show cookie information.
What we've tried:
Occurs for GET requests but not POST requests
Occurs without a view (NOT a javascript issue)
Browser does not show two requests. This occurs server-side.
Does not occur in Firefox Privacy Mode
Does not occur on localhost. Only in production.
Occurs with HTTPS off
Fork of the solution does not exhibit this behavior (makes middleware unlikely cause)
Best guesses:
.NET 5 (deprecated) or dependencies (a bad developer blames his tools)
IIS Settings
Session
Code example:
Controller
// no other filters
[HttpGet]
public IActionResult DupeRequestTest()
{
// database insert with Dapper
var sql = #"INSERT INTO TrackingTable
(CookieJson, CreateDate)
VALUES(#CookieJson, GETDATE());";
using var con = new SqlConnection(_connectionString);
con.Open();
con.Execute(sql, new
{
CookieJson=JsonConvert.SerializeObject(Request.Cookies),
});
// returning a status code so no View, javascript, or other requests
return StatusCode(200);
}
Database results:
CookieJson
CreateDate
[{"Key":"SessionId","Value":"ac6f292c-1ca1-5179-9123-78a04d382dea"}]
2022-10-25 09:46:30.523
[]
2022-10-25 09:46:30.770
Thank you. Any help, such as next testing steps, would be appreciated - short of building a new app.
I'm sure the answer is either very stupid or very hidden.
I have a WCF RESTful Web Service (using webHttpBinding) that is returning a 400 when I try to call a web service method on it.
If I go to mywebservice.svc, I get the standard WCF web service page. But if I go to /mywebservice.svc/some/rest/service/url, I get an Http 400. Every single time. Doesn't matter the parameters, or the method being called.
Here's what we've looked at so far:
Looked at IIS Express logs. There is no Win32 status (i.e. status 0) to go along with the HTTP Status
Turned on WCF logging. Nothing is logged by WCF, which suggests the request isn't even making it that far.
Tried debugging our method, but the breakpoint never gets hit.
Tried running the service under Cassini. Same result (http 400).
Tried another user on the problematic machine. Same result.
We know that this works on other machines. The problematic machine is using VS 2010 on Win XP. We are using WCF 4.0
I know there isn't much to go on here because we don't have a specific error message, but given where we've looked, does anybody have any suggestions on where to look next?
UPDATE: Added Code Samples
Here is the definition of my with one method, and the implementation of that method.
[ServiceContract]
public interface IMAMDataWebService
{
[WebGet(UriTemplate = "/Contracts/{taxID}", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
ContractCollection Contracts(string taxID);
}
public ContractCollection Contracts(string taxID)
{
ContractCollection contracts = new ContractCollection();
try
{
contracts = _contractService.GetContracts(taxID);
}
catch (RstsException rEx)
{
if (!rEx.Logged)
_errorLogger.LogError(rEx);
WebFault.ThrowFault(rEx, HttpStatusCode.InternalServerError);
}
catch (Exception ex)
{
RstsException rEx = new RstsException(ex);
_errorLogger.LogError(rEx);
WebFault.ThrowFault(rEx, HttpStatusCode.InternalServerError);
}
if (contracts.Count == 0)
{
WebFault.ThrowFault(Strings.ObjectNotFound, HttpStatusCode.NotFound);
}
return contracts;
}
I'm calling it with a web browser, i.e. MAMDataWebService.svc/Contracts/123456789
I'm convinced this has to be a permissions problem, but I"m not sure what. It works on all our Win 7 machines using VS 2010, but a few users still have XP and they're the ones with the problem. But without any errors, it's hard to tell what's going on.
I've created a plugin and registered it using hte registration tool. I've also added a step that is supposed to handle a message of creation of an instance. Sadly, the intended behavior doesn't occur.
My guess is that something inside the plugin crashes but I have no idea on how to debug it. Setting up breakpoints is not going to work agains on-line version, I understand, so I'm not even trying.
For legal and technical reasons, I won't be able to lift over the solution to an on-premise installation, neither. Is guessing my only option?
For server-side (plugins) I'm using ITracingService. For client-side I log everything to console. The downside with the first is that you actually need to crash the execution to get to see anything. The downside with the latter is that plugins sometimes get executed without GUI being invoked at all.
When it comes to heavier projects, I simply set up a WCF web service that I call from the plugin and write to that. That way, on one screen, I'm executing the plugin while on the other, I'm getting a nice log file (or just put the sent information to on the screen).
You could, for instance, start with a very basic update of a field on the instance of your entity that's being created. When you have that working, you can always fall back to the last working version. If you don't even get that to work, it mean, probably, that you're setting up the plugin registration incorrectly.
A very efficient way would be to lift over the solution to an on-premise version where you have full control but I see in your question that it's not en option.
In case you could lift the solution to an on-premise version, here's a link on how to debug plugins.
Don't forget that you also have access to the ITracingService.
You can get a reference to it in your Execute method and then write to it every so often in your code to log variables or courses of action that you are attempting or have succeeded with. You can also use it to surface more valuable information when an exception occurs.
It's basically like writing to a console. Then, if anything causes the plug-in to crash at runtime then you can see everything that you've traced when you click Download Log File on the error shown to the user.
Beware though - unless your plug-in actually throws an exception (deliberate or otherwise) then you have no access to whatever was traced.
Example:
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(
typeof(IPluginExecutionContext));
// Get a reference to the tracing service.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
tracingService.Trace("Getting entity from InputParameters...");
// may fail for some messages, since "Target" is not present
var myEntity = (Entity)context.InputParameters["Target"];
tracingService.Trace("Got entity OK");
// some other logic here...
}
catch (FaultException<OrganizationServiceFault> ex)
{
_trace.Trace(ex.ToString());
while (ex.InnerException != null)
{
ex = (FaultException<OrganizationServiceFault>)ex.InnerException;
_trace.Trace(ex.ToString());
}
throw new InvalidPluginExecutionException(
string.Format("An error occurred in your plugin: {0}", ex));
}
catch (Exception ex)
{
_trace.Trace(ex.ToString());
while (ex.InnerException != null)
{
ex = ex.InnerException;
_trace.Trace(ex.ToString());
}
throw;
}
}
I'm running a mixed MVC Application inside a sub folder of a web forms application.
Everything worked great in VS 2010 debug (Cassini) but when I deployed to IIS7.5
I got the following error:
'HttpContext.SetSessionStateBehavior' can only be invoked before
'HttpApplication.AcquireRequestState' event is raised.
It errors on the last line (httpHandler.ProcessRequest(HttpContext.Current);) in the default.aspx file of the MVC application sub folder.
public void Page_Load(object sender, System.EventArgs e)
{
string pathToRewriteTo = Request.Path.ToLowerInvariant().Replace("default.aspx", "Home/Index");
HttpContext.Current.RewritePath(pathToRewriteTo, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
}
However if I manually navigate to Home/Index from the MVC root folder I can see my application fine from there.
I've looked up the error being thrown and I only find answers dealing with server transfers and not MVC routes.
I have also already checked my IIS7.5 configuration for the route handling module, Application pool running in integrated mode, etc.
Any help would be appreciated.
We faced a similar issue. There are changes to MVCHttpHandler in MVC2 and above.
You need to change it to use httpContext.Server.TransferRequest.
Try the below snippet:
var httpContext = HttpContext.Current;
httpContext.Server.TransferRequest(Url, true); // change to false to pass query string parameters if you have already processed them
I have read all other posts and have been googling this for the last 2 hours! I started WCF Data Services about 3 hours ago btw.
My service is on an asp.net4 app, the ado entity model exposes an sql server db.
Here is FasDataService.svc.cs
public class FasDataService : DataService<FASStoreEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config.UseVerboseErrors = true;
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}
I have then a winforms 4 app with the following code in the Main()
FASStoreEntities fas = new FASStoreEntities(u);
var a = from al in fas.Customers
where al.Name == "Alinio"
select al;
MessageBox.Show(a.First().Phone1);
When I run the web app and point to http://localhost:15995/FasDataService.svc/Customers(1) it loads up the one and only customer in there
My error is WebException was unhandled:
The operation has timed out. The inner
exception is null.
Also, everything is local but when I do this (in chrome) it takes a good load of time! Its scary to think of how it would perform in production?
For some reason, today I installed fiddler and tried it and it works! I also, queried the service with linqpad and it worked no prob!
Although throughout today I played with wcf data services and had tons of problems accessing data because of all kinds of errors, data connection was still open, some error insert excess data in a field etc etc.
Fiddler was very helpful at diagnosing what the error was, its very difficult to figure out what really went wrong so fiddler is a must have.