I am trying to do PayPal IPN method. So I thought since I am doing asp.net mvc I can just make a method view in my controller like this
public void IPN()
{
// IPN code
}
So I tried this all on local host made my own form to post some IPN variable stuff and it worked fine. I uploaded it to my server and used the IPN simulator from paypal and it kept return a server 500 error.
So I took all the code out and basically had what you see about just a empty method in my controller. So I tried teh simulator again and it failed again with a server 500 error.
So I went and actually typed in my url to that controller method and I get this stack trace.
[NullReferenceException: Object reference not set to an instance of an object.]
site.com.Controllers.MyTestController.IPN() in MyTestController:2320
lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
System.Web.Mvc.Controller.ExecuteCore() +123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
I am not sure if MyTestController:2320 is refering to line 2320(because it does not exist) or what.
Thanks
Those numbers on the right are offsets into the compiled code, so they won't point to any source code line numbers.
What I'd do in this scenario is to put some kind of logging into the code, so that I can know where in the code the exception is raised. Depending on what access you have to the server you uploaded the code to, you might be able to create a log file, or event log, etc, and use Trace statements:
Trace.WriteLine("Controllers.MyTestController.IPN(): Creating object.")
Dim o As New Object
Trace.WriteLine("Controllers.MyTestController.IPN(): Call PayPal web service.")
Call PayPal.GetAccountNumber()
Doing this would help you spot where in the code the failure is happening.
Without seeing the code we can't be sure where the NullReferenceException happening.
But, having experience setting up an IPN myself, I think you are most likely referencing a null string object. For example :
string foo = Request.Form["bar"];
foo.Trim();
//if the form collection doesn't contain a value for the key "bar" then it'll
//throw a NullReferenceException on foo.Trim()
Just make sure you are not calling any methods, properties on any object without making sure they're not null.
Related
have copied sample xero API wrapper in C# from github. But when same code is copied into the current MVC3 project, it gives a Object reference not set to an instance of state .
the relevant code is as follows:
Home controller method:
public ActionResult Index()
{
IOAuthSession oauthSession = ServiceProvider.GetCurrentSession();
Repository repository = ServiceProvider.GetCurrentRepository();
// Can we already access an organisation??
if (oauthSession.HasValidAccessToken && repository != null && repository.Organisation != null)
{
return new RedirectResult("~/");
}
if (oauthSession is XeroApiPrivateSession)
{
throw new ApplicationException("The current private session cannot access the authorised organisation. Has the access token been revoked?");
}
// Determine the callback uri to use - this must match the domain used when the application was registerd on http://api.xero.com
var callbackUri = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Url.Action("Callback"));
// Call: GET /oauth/RequestToken
RequestToken requestToken = oauthSession.GetRequestToken(callbackUri.Uri);
// error comes here...
string authorisationUrl = oauthSession.GetUserAuthorizationUrl();
return new RedirectResult(authorisationUrl);
}
the full error is as follows:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 45:
Line 46: // Call: GET /oauth/RequestToken
Line 47: RequestToken requestToken = oauthSession.GetRequestToken(callbackUri.Uri);
Line 48:
Line 49: string authorisationUrl = oauthSession.GetUserAuthorizationUrl();
Source File: \Xero\Xero\Xero\Xero\Controllers\HomeController.cs Line: 47
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
DevDefined.OAuth.Consumer.OAuthSession.GetRequestToken(Uri callbackUri) in n:\w2\861c2b03515ac7b6\source\XeroApi\OAuth\Consumer\OAuthSession.cs:181
Xero.Controllers.HomeController.Index() in i:\Softech projects\Xero\Xero\Xero\Xero\Controllers\HomeController.cs:47
lambda_method(Closure , ControllerBase , Object[] ) +101
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +435
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +60
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +145
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +433
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +72
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +323
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +844
System.Web.Mvc.Controller.ExecuteCore() +130
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +229
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +71
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +152
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +38
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +31
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +61
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +118
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514812
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
any help appreciated.
the aim is to connect to xero api and use its methods. if there is any working methods for C#, please inform if possible
The line throwing the exception is used for obtaining unverified request token from Xero. Without knowing much what you have done to setup the app, it appears that you have not registered your app with Xero and have not added your consumer key and secret in Web.config.
For a Xero public app, these settings are required:
<!-- Consumer Key and Secret, taken from an public/partner application registered at http://api.xero.com -->
<add key="XeroApiConsumerKey" value="xxxxxxxxxxxx"/>
<add key="XeroApiConsumerSecret" value="xxxxxxxxxxxxxxxxxxx"/>
<!-- SignatureMethod. Use 'HMAC-SHA1' for public apps, 'RSA-SHA1' for private and partner apps. -->
<add key="XeroApiSignatureMethod" value="HMAC-SHA1"/>
<!-- Xero API Endpoints
Use 'https://api.xero.com/' for public and private apps
Use 'https://api-partner.network.xero.com/' for partner apps
-->
<add key="XeroApiBaseUrl" value="https://api.xero.com/"/>
In your app setup at Xero developer website, make sure to use right domain name. For example, if you are running your app on your local host (say for testing), enter localhost in domain name field in your registered app at Xero.
If all these settings are properly made, there is no reason why it wouldn't work. You can ask me if you run into other issues.
[By the way, referring to the exception you have posted, you can always open Xero API source and find out what is line 181 of OAuthSession.cs so that you know what object is not being populated.]
I am in the process of identifying a framework for building a local OAuth (2.0) Provider with a good client library (there aren’t many), at a glance DotNetOpenAuth seems to be ideal and I got excited and wanted to try out the samples.
I spent few days fiddling with the sample and the source itself still I couldn’t figure out a way to get the OAuth2\AuthorizationServer sample working. Sample works fine for all other external providers. I went through numerous posts to figure out ideal setup, inputs, settings to get pass initial login screen but I had no luck.
Can someone please share the initial steps to be followed to get the OAuth2\AuthorizationServer sample up and running. Including the database setup. I tried stepping through the code but lost it.
Appreciate your time. I am very happy to document the steps if I can understand them clearly. I think the framework is excellent but documentation is lacking. Thanks again!
This is the error I am getting,
DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
I’ve used relying party URI as inputs,
http:// localhost:59722 /
http:// localhost:59722 /SampleWcf2.aspx
And the full stack trace,
DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 352
--- End of inner exception stack trace ---
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 354
at OAuthAuthorizationServer.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in D:\Temp\dotnetopenid\samples\OAuthAuthorizationServer\Controllers\AccountController.cs:line 40
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
2012-06-15 16:08:03,490 (GMT+10) [16] DEBUG DotNetOpenAuth.Http - HTTP GET http://localhost:59722/SampleWcf2.aspx
2012-06-15 16:08:03,498 (GMT+10) [16] DEBUG DotNetOpenAuth.Yadis - HTML discovery failed to find any endpoints.
2012-06-15 16:08:03,498 (GMT+10) [16] INFO DotNetOpenAuth.Yadis - Performing discovery on user-supplied identifier: http://localhost:59722/SampleWcf2.aspx
2012-06-15 16:08:03,498 (GMT+10) [16] DEBUG DotNetOpenAuth.Yadis - Filtering and sorting of endpoints did not affect the list.
2012-06-15 16:08:03,578 (GMT+10) [16] ERROR DotNetOpenAuth.OAuthAuthorizationServer - An unhandled exception occurred in ASP.NET processing: DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 352
--- End of inner exception stack trace ---
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 354
at OAuthAuthorizationServer.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in D:\Temp\dotnetopenid\samples\OAuthAuthorizationServer\Controllers\AccountController.cs:line 40
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 352
--- End of inner exception stack trace ---
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 354
at OAuthAuthorizationServer.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in D:\Temp\dotnetopenid\samples\OAuthAuthorizationServer\Controllers\AccountController.cs:line 40
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
strong text
It sounds like you're confusing OAuth 2.0 authorization servers with OpenID 2.0 Providers. They are totally different. When "logging in" to the authorization server sample, which appears to be the failure point in your original question, you need to enter a valid OpenID. The URLs you were trying appear to be URLs to the OAuth 2.0 client sample, which isn't an OpenID.
You should log into the authorization server using identifiers like those supplied by the OpenIdProvider sample, or (most easily) just use "yahoo.com" if you have a Yahoo account or "tinyurl.com/googop" to log in using Google.
Unless I'm mistaken (which isn't entirely unlikely) the AuthorizationServer sample pretty much acts as a gateway which validates OAuth requests by authorizing the user against an OpenID provider. Instead of putting the relying party's URL in, you might try putting in an OpenID provider URL. (even for testing, you should be fine using any of the public providers you may have an account with)
Here's the line where I get that error:
var requestToken = OAuthUtility.GetRequestToken(
_consumerKey,
_consumerSecret,
"http://mysite.com/Twitter/GetToken");
_consumerKey and _consumerSecret have proper values.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: String]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9585854
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
Twitterizer.TwitterizerException.ParseRateLimitHeaders(WebResponse response) in C:\Projects\twitterizer-132\Twitterizer2\Exceptions\TwitterizerException.cs:200
Twitterizer.TwitterizerException..ctor(String message, Exception innerException) in C:\Projects\twitterizer-132\Twitterizer2\Exceptions\TwitterizerException.cs:98
Twitterizer.OAuthUtility.GetRequestToken(String consumerKey, String consumerSecret, String callbackAddress) in C:\Projects\twitterizer-132\Twitterizer2\OAuth\OAuthUtility.cs:95
Brace.Twitter.Tweeting.GetRequestTokenUrl() in D:\PROJECTS\Brace\v1\Brace.Twitter\Tweeting.cs:18
Brace.Controllers.TwitterController.GetToken(String oauth_token, String oauth_verifier) in D:\PROJECTS\Brace\v1\Brace\Controllers\TwitterController.cs:15
lambda_method(Closure , ControllerBase , Object[] ) +157
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27
System.Web.Mvc.<>c_DisplayClass15.b_12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult ) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c_DisplayClasse.b_d() +50
System.Web.Mvc.SecurityUtil.b_0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Here's my best attempt at being overly vague: this bug is actually a symptom of another issue.
More than likely, your application (not your actual application, but the registration with Twitter that gave you your console token) is not set up as a web application. Their form is misleading: it doesn't make the callback url required when you select a web app, but it actually is required. When you save your app without a callback url, it actually saves it as a desktop app.
The problem with a desktop app is that you can't use callback urls. Web apps can used pin-based authentication, but desktop apps can't use web-based authentication. (I'm sure there's a perfectly good reason.)
So, twitter is rejecting your request to get a request token, because you're also providing a callback.
The actual exception is because Twitterizer is still looking for rate limit information that's included in every (well, ok, almost-every) response, even from requests that failed.
I will (finally) fix that issue, but it won't solve your real problem.
I've developed an application with ASP.NET MVC 2, and after deploying it, I get an InvalidCastException:
Error/Exception: "Specified cast is not valid."
Stacktrace:
[InvalidCastException: Specified cast is not valid.]
System.Data.SqlClient.SqlBuffer.get_Time() +77
System.Data.SqlClient.SqlDataReader.GetTimeSpan(Int32 i) +56
Read_Question(ObjectMaterializer`1 ) +1740
System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +29
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +7667556
System.Linq.Enumerable.ToList(IEnumerable`1 source) +61
TestEnvironment.Managements.QuestionManager.GetquestionsByTestId(Int32 testId) in D:\ParallelMinds\Projects\TestApplication\TestEnvironment\TestEnvironment\Managements\QuestionManager.cs:131
TestEnvironment.Controllers.LoadTestController.Index(Nullable`1 testId) in D:\ParallelMinds\Projects\TestApplication\TestEnvironment\TestEnvironment\Controllers\LoadTestController.cs:31
lambda_method(ExecutionScope , ControllerBase , Object[] ) +86
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +300
System.Web.Mvc.Controller.ExecuteCore() +104
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +36
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +53
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +30
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8681102
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Why am I getting this error only when I deploy the application? It works fine in my local development server, and I only get this exception on one page.
Without any more details I would guess that the table you are accessing on your deployment database is inconsistent with the table on your development database.
Maybe you have a column that is of a different type on your local machine.
Either that or there is some invalid data in the record you are retrieving in the deployment database.
The error Specified cast is not valid is encountered when one type cannot be directly cast to another.
Usually, this mistake is made when the programmer thinks they have one type, but actually have another. Take for example a textbox which has been constrained to only accept numbers. A programmer might well read the value, and later on make the mistake of expecting it to be a number
string myValue = myTextBox.Text;
// later
someComponent.ValueExpectingANumber = (int)myValue; // specified cast is not valid
in the above example, the number would have to be "Parsed" rather than cast.
It looks to me like something in your Read_Question method is filling in a field that's supposed to be SQL-compatible date or time value, and whatever the method is putting into the value is improperly formatted. The System.Data.SqlClient.SqlBuffer.get_Time() method tries to convert that value to a SQL date/time and throws an exception.
The first place I would look is in the Read_Question method.
If this happened when you published the DB, it could be that the culture is different for that server instance. For example, the differences in the english and american versions of the date.
Alternatively, if you are using DateTime.MinValue, the DateTime.MinValue differs from the range accepted by sql server; instead use the SqlDateTime object.
Can you post the code that is calling this method?
Matt
I'm frustrated... my site has suddenly become very unstable. So much so that hitting refresh over and over will cause it to crash. To investigate, I turned off all error handling so I could see some YSOD's.
Instead of trying to write it all out, I made a video showing the issue. You can see it here on YouTube.
Here's a copy of the stacktrace:
[InvalidCastException: Specified cast is not valid.]
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +847
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +113
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +344
System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +23
System.Linq.Queryable.Count(IQueryable`1 source) +240
MvcPaging.PagedList`1.Initialize(IQueryable`1 source, Int32 index, Int32 pageSize, Nullable`1 totalCount) in C:\Users\BikGame\Desktop\src\MvcPaging\PagedList.cs:63
MvcPaging.PagedList`1..ctor(IQueryable`1 source, Int32 index, Int32 pageSize, Nullable`1 totalCount) in C:\Users\BikGame\Desktop\src\MvcPaging\PagedList.cs:25
MvcPaging.PagedList`1..ctor(IQueryable`1 source, Int32 index, Int32 pageSize) in C:\Users\BikGame\Desktop\src\MvcPaging\PagedList.cs:19
MvcPaging.PagingExtensions.ToPagedList(IQueryable`1 source, Int32 pageIndex, Int32 pageSize) in C:\Users\BikGame\Desktop\src\MvcPaging\PagingExtensions.cs:63
ApoAds.Controllers.HomeController.Index() in C:\Users\BikGame\Documents\Visual Studio 2008\Projects\APOAds-MultiBaseBiz\Controllers\HomeController.cs:22
lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
System.Web.Mvc.Controller.ExecuteCore() +123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
On the page that's trying to load there are two ajax calls to views that hit the database, render a table and return html. Portions of the menu at the top of the site are pulled from the database and then cached to prevent multiple return trips. Hosting is on IIS6 in a medium trust, shared environment.
Crazy how it works and then stops working for 3-4 minutes and then works again... perhaps a sql connection hanging and then timing out after a few minutes?
Any ideas would be very greatly appreciated! Thanks in advance!
Update: added data access code
I'm using LINQ to SQL in a repository pattern. Here's a query that one of the AJAX calls is using.
public IQueryable<Ad> FindAdsPerBase(string baseName, AdStatus status)
{
return (from ad in _db.Ads
join b in _db.AdBases on ad.AdID equals b.AdID
where b.MilBase.BaseName.ToLower() == baseName.ToLower() && ad.Status == (byte)status
select ad).Distinct().OrderByDescending(x => x.DateEntered);
}
and it is called in the controller like so:
var ads = _db.FindAdsPerBase(MilBase, AdStatus.Active).Take(11);
You haven't given nearly enough information to troubleshoot, and (no offense) I'm not heading over to YouTube to watch a video. Here are some general troubleshooting steps I'd take and questions I'd ask myself:
When it fails, is it always the exact same exception? Or does it vary? If the same exception is always thrown then there might be a defect in your logic somewhere. If you get totally random exceptions then you may have a hardware or infrastructure issue.
First thing to do when you get LINQ to SQL exceptions is hook up SQL Profiler to see the exact query statement being sent to the server. Copy/paste that into SQL Management Studio and run it by hand. Look at the results and compare them to the data types of the object you're loading: is the query mapping an empty value to a non-nullable field? Maybe a query column is being mapped to a property of a different type?
If it works for 3-4 minutes, then stops for 3-4 minutes, then works again, look for any time-specific code in your project. Are you doing any caching? Maybe the issue is related to the behavior that occurs when the cache is stale versus when it's not stale, or vice versa. Maybe you have a date/time calculation that overflows or does something funky for certain inputs?
Hook up a debugger and have it catch the exception. Then walk up the stack trace and look at the program state during a failure. Compare it to the program state when the app is working correctly. Anything stand out?
You may have changed something in your database (like datatype of a column) without remembering to re-create your LINQ classes. Thus LINQ to SQL may be causing that casting exception.