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)
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.]
NET MVC3 with Entity Framework 5 (DB First) application and all of the access to the db raises the same error
The requested name is valid, but no data of the requested type was found
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.Net.Sockets.SocketException: The requested name is valid, but no data of the requested type was found
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SocketException (0x2afc): The requested name is valid, but no data of the requested type was found]
System.Net.Dns.GetAddrInfo(String name) +6603626
System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6) +106
System.Net.Dns.GetHostEntry(String hostNameOrAddress) +109
MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname) +75
[Exception: Call to GetHostEntry failed after 00:00:00 while querying for hostname 'xxxxxxxx.db.1and1.com': SocketErrorCode=NoData, ErrorCode=11004, NativeErrorCode=11004.]
MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname) +349
MySql.Data.Common.StreamCreator.GetHostEntry(String hostname) +36
MySql.Data.Common.StreamCreator.GetStreamFromHost(String pipeName, String hostName, UInt32 timeout) +70
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +204
MySql.Data.MySqlClient.NativeDriver.Open() +370
[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
MySql.Data.MySqlClient.NativeDriver.Open() +428
MySql.Data.MySqlClient.Driver.Open() +22
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +218
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +287
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +93
MySql.Data.MySqlClient.MySqlPool.GetConnection() +65
MySql.Data.MySqlClient.MySqlConnection.Open() +543
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +44
[EntityException: The underlying provider failed on Open.]
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +203
System.Data.EntityClient.EntityConnection.Open() +104
System.Data.Objects.ObjectContext.EnsureConnection() +75
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +41
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +36
System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() +72
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +23
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +369
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
domvaproject.Controllers.PropiedadesController.Index() +21
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +182
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9628700
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
My hosting provider (1and1) tells me that the problem is mine, but i think that this problem is caused by some error in DNS. They told me that the error is in the code but it crashes on every connection
I got the same error due to my connection string. It included a port number, but the correct connection string has to be like this:
<add name="myConnectionString" connectionString="Server=localhost;Database=mydatabase;Uid=root;Pwd=password;Allow Zero Datetime=true" providerName="MySql.Data.MySqlClient"/>
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 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.