.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Post New Web Links

Unable to catch WCF EndpointNotFound exception in SecurityToken.GetToken( . )

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
I have a set of WCF services that I am integrating with, I can not change them in any way because they are provided by a third party. I use a username/password scheme to authenticate with the services. If the services are not available I get an exception (EndPointNotFoundException) from the SecurityTokenProvider class that I can not catch. I understand why the exception is being thrown, I just need to know how I can handle it so that I can gracefully handle the errors in the user interface. Is there a way I can catch this exception or a better way to handle this scenario? The Exception The exception is thrown from System.IdentityModel.Selectors.SecurityTokenProvider : GetToken( TimeSpan timeout ) public SecurityToken GetToken(TimeSpan timeout) {    SecurityToken token = this.GetTokenCore(timeout);     if (token == null)    {        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.TokenProviderUnableToGetToken, this)));    }     return token;} The channel open part When I open the channel I have it wrapped in exception handling, but none of it seems to trap the SecurityToken exception. I am using the ExceptionHandlingProxyWrapperBase try{    this.Open();} catch( EndpointNotFoundException epnfe ){    // Handle the exception} catch( E

View Complete Post

More Related Resource Links

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

reader.getordinal("column_may_not_exist") how to catch the exception?



would any body please help me to catch the exception if the column doesnot exist as my table columns are not static.

sometimes its throwing me indexoutofrange exception as the column doesnot exist

thanks for the help guys

How to CATCH "Invalid postback or callback argument" exception?



How can I catch this exception? I do not want it to stop my page execution. Can/Should I do that?

Server Error in '/' Application.
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
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.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally

Rare exception: Unable to read data from the transport connection: An existing connection was forcib

Our .NET 2.0 app relies upon the ability to download xml webpages from URLs.  At startup, we have about 6 boxes in the wild (out of thousands) that are seeing the following inner exception when they try to download an xml page.  System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. (Inner: ) System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. They can get to the URL in their browser just fine, so we know our server is working.  Furthermore, the embedded WebBrowser control in our app can pull up webpages just fine, so I don't think their firewall is blocking our app.  I'm hoping it's just some diagnosible configuration issue.  Here is the snippet of code that does the downloading: WebRequest request = WebRequest.Create(fileToDownload.SourceUri);request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);request.Timeout = (int)DefaultTimeout.TotalMilliseconds;request.Method = "HEAD";WebResponse response = request.GetResponse(); Nothing revolutionary there. (I've also tried it without the HEAD request, without keepalive, and using HTTP 1.0).  And here is the exception: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. StackTrace Infor

unable to config the enterprise library exception handling for oracle

Hi unable to config the enterprise library exception handling for oracle any help?   Thanks in advance :-)

Getting 'Unable to create mutex' exception using IsolatedStorage

Getting the following exception when trying to use IsolatedStorage on a windows 7 machine.  This same code works fine on Windows XP or Vista.  Any insight would be most helpful. Thanks CD Sample method: public static IsolatedStorageFileStream GetIsolatedStorageFileStream(string fileName,FileMode fileMode)         {                          IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly();                          IsolatedStorageFileStream fileStream;             string existingFile = FindExistingStorageFile(isolatedStorageFile, fileName);             if(!(String.IsNullOrEmpty(existingFile)))             {                 fileStream = new IsolatedStorageFileStream(fileName, fileMode, isolatedStorageFile);             }             else             {                 fileStream = new IsolatedStorageFileStream(fileName, FileMode.Create, isolatedStorageFile);             }             return fileStream;                      } when trying to access the returned stream, I am receiving the following exception. Top Exception Type=System.IO.IsolatedStorage.IsolatedStorageException Source=mscorlib Message=Unable to create mutex. (Exception from HRESULT: 0x80131464) StackTrace: at System.IO.IsolatedStorage.IsolatedStorageFile.nOpen(String infoFile, String syncName) at System.IO.IsolatedStorage.IsolatedStorageFile.Lock() at System.IO.Isolate

No return from unmanaged code, methods to catch exception?


I am developing a c# application that needs to calls functions from a c header file. I use

[System.Runtime.InteropServices.DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true,SetLastError=true)]
        public static extern Byte xxxx(IntPtr hResourceContext, ushort xxxx, ref structa aaa,ref Result_struct Result, Byte b);

to import the dll method. When I call this method in C#, the application simply exits without throwing an exception or error. I've used similar approach for other methods from the same dll which involves passing nested structs as parameter and they work fine. I would like to know how I can debug the code/ catch errors/exceptions from the unmanaged code.

I tried to include the SetLastError=true during DllImport but it does not help.


Empty Catch in Global.asax to prevent exception from stopping a web application?



I'm using a static Timer in my Global.asax to run a method at regular intervals. When the method throws an exception, my application is stopped. I have used an empty catch to prevent exceptions from stopping the application something like below code. Is there a disadvantage to use such an approach?


 protected void Application_Start(object sender, EventArgs e)

 public class TimerStarter
            private static System.Threading.Timer threadingTimer;

            public static void StartTimer()
                if (null == threadingTimer)
                    threadingTimer = new System.Threading.Timer(new System.Threading.TimerCallback(CheckData),HttpContext.Current, 0, 50000);

            private static void CheckData(object sender)
                   // a method that reading xml file from another url              
                    // empty catch to prevent stopping the application




Getting Exception info from catch block to Application_Error event of HttpModule


I need some help regarding one issue I am facing. I created a httpmodule for hadling the unhandled errors and I need to log those errors using log 4 net in database.

Everting working fine but I am not getting any error information once the error was hadled and I need that info too. I want to make it as a centralize module which can trap all errors and log those errors.

How call application_error event of httpmodule from catch block...so that I can log that info there and I no need log in every catch block..


Error given but unable to catch it


Hi everyone,

I've been working on this project which requires me to insert data into a database. Due to the complexities of the function that I am doing, it is more complex to use SqlDataSource and hence I've used the traditional method of inserting to the database.

The codes are as follows:

 Private Sub reviewFV_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles reviewFV.ItemInserting
        Dim textboxcomment As TextBox = reviewFV.FindControl("commentTB")
        Dim comments As String = textboxcomment.Text

        Dim reviewId As String = generateReviewID()

        'get connection string from web.config
        Dim strConn As String = ConfigurationManager.ConnectionStrings("ProrsumDBConnectionString").ConnectionString
        'create sql connection

        Dim myConn As New SqlConnection(strConn)
        'Open connection; Note: You need to open a connection to database

            Dim cmd As String = "INSERT INTO Review(reviewID, comments, reviewDate, custID, sessionID, tourID) VALUES (@reviewID, @comments, @reviewDate, @custId, @sessId, @tourId)"
            Dim myCmd As New SqlCommand(cmd, myConn)

            Dim tid As String = Session("tid")
            Dim sid As String 

throw and catch exception handling



iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if  any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
                        int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
                        if (updaterec > 0)
                            running = true;
                            DataSet BillContainerDetails = BillingDetails();

WCF REST Catch Exception ClientSide


I am using WcfRestContrib which allows me to throw a WebException from the server (among other things). Very Similar to how the Rest Starter Kit allows with WebProtocolException. This sets the proper return code and a helper string. (this is visible in a browser so I know it does work)

I am using the WebChannelFactory for the client side. What I would like to do is try to catch this message on the client side but am unable to do so. The client receives a ProtocolException with a brief explanation about the error code.

I added a custom Behavior to the client side to add a message inspector but the exception is thrown before the AfterReceiveReply call is made. How can I accomplish what I am looking for?

Please Help! Thanks!

Unable to cast COM Object - Exception


Hi everyone,

Ive been trying to develop a COM Client application, but without success. My goal is to create an application that can open reports in Cognos Impromptu. Ive got Cognos Impromptu installed on this machine and im using Visual Studio 2008 to develop the client.

I created my project as a consoleapplication in Visual Studio. Next, I added the Impromptu Client Reference via Project > Add Reference > COM. All works fine till now, Visual Studio creates my COM Wrapper dll and adds it to the bin/debug folder.

But when I trry to run my program, it gives me the following Exception:

Unable to cast COM object of type 'ImpromptuClient.ImpromptuApplicationClass' to
 interface type 'ImpromptuClient.IAppAuto'. This operation failed because the Qu
eryInterface call on the COM component for the interface with IID '{2F835754-FB4
F-11CF-8E5F-00401C60350D}' failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Press any key to continue . . .

The code I use is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.

Unable to load DLL 'foo.dll': The specified module could not be found. (Exception from HRESULT: 0x

I have .Net 1.1  Application that works fine with the same dll, after redesigning application to 2.o Framework I have this error, I tried to compile it with /MT (this is C++ project in ANSI C, planned to be working on different platforms), but had no luck. Even tryed to make dummy dll  with function doing nothing - still didn't work. What can be problem and how to fix it?

Windows Service crash - catch exception


A windows service written in C# is intermittently crashing on a server. If I want to log the reason for crash, can I add try catch block in OnStop method?

will onStop  method get initiated on crashing?

protected override void OnStop()

SQL Server try-catch inner exception message conundrum



The following SQL statement below is a good example of some SQL that throws an exception with nested details. It seems in the catch part of the statement I can only get outer exception details Could not create constraint. See previous errors (not very useful!). What I want to get is the inner exception message:

Introducing FOREIGN KEY constraint 'FK_TWO' on table 'TABLE2' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints (you can get this message by running the code without try-catch).

In the Catch block, how can this be achieved in T-SQL? If not is this something that can be fixed in SQL going forward, where can I send this request?


      CHAR(50) NOT NULL);



Exception Error 5123 - Unable to attach database




Our GIS group is working with SQL Server 2005 in conjunction with ESRI's ArcGIS software. SQL Server is being used as a test bed until we formally migrate our existing Microsoft Access mdb's over. So, at this time we are conducting various tests and have the freedom to "blow up" our databases.


We are currently testing ArcSDE Workgroup edition, which will only work with SQL Server Express (SSE). SSE will let us create spatial joins and relationships, while maintaining data integrity. So one possible workaround was to detach the database from SQL Server 2005 and then attach it to SSE. Unfortunately, we ran into a problem in re-attaching the database back to SQL Server 2005.


The exact steps are as follows:

  1. Back up database using back up tool in SQL Server 2005.
  2. Detached database from SQL Server 2005.
  3. Attached database to SQL Server Express (hereafter SSE).
  4. Created a table in database while it was attached to SSE.
  5. Detached database from SSE.
  6. Attempt to attach database to SQL Server 2005 failed
  7. Succe
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend