Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8111371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:05:25+00:00 2026-06-06T02:05:25+00:00

When an external library contains a LINQ provider, and it throws an exception when

  • 0

When an external library contains a LINQ provider, and it throws an exception when executing a dynamic expression tree, how can I break when that expression is thrown?

For example, I use a third party LINQ2CRM provider, which allows me to call the Max<TSource, TResult>() method of IQueryable, but when it throws an InvalidCastException, I fail to break on the spot when the exception is thrown, making it hard to review the stack-trace because it’s already unwinded when the debugger breaks it in my code. I’ve set “break on throw” for the mentioned exception. My debug settings are:

enter image description here


Clarification on where exactly I’d want to break. I do not want to break in side the LINQ Expression, but instead, I want to break when the expression tree is executed, or, put in other words, when the IQueryable extension method Max() calls the override provided by the LINQ provider. The top of the stacktrace looks like this, which is where I would like to break inside (or step through, or whatever):

at XrmLinq.QueryProviderBase.Execute[T](Expression expression)
at System.Linq.Queryable.Max[TSource,TResult](IQueryable`1 source, Expression`1 selector)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:05:28+00:00Added an answer on June 6, 2026 at 2:05 am

    I may not be understanding the problem, but instead of actually breaking on the line (which doesn’t appear to be possible), would it be enough to put a try-catch inside your expression tree and log the exception?

    static void Main(string[] args)
    {
        var logExceptionMethod = typeof (Program).GetMethod("LogException", BindingFlags.Static | BindingFlags.NonPublic);
        var createFileMethod = typeof (System.IO.File).GetMethod("Create", new[] {typeof(string)});
    
        // Parameter for the catch block
        var exception = Expression.Parameter(typeof(Exception));
    
        var expression =
            Expression.TryCatch(
            Expression.Block(typeof(void),
                // Try to create an invalid file
                Expression.Call(createFileMethod, Expression.Constant("abcd/\\"))),
    
                // Log the exception from the catch                  
                Expression.Catch(exception, Expression.Call(logExceptionMethod, exception)));
    
        Expression.Lambda<Action>(expression).Compile()();
    }
    
    static void LogException(Exception ex)
    {
        Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
    }
    

    Console output:

    The filename, directory name, or volume label syntax is incorrect.
    
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
    at System.IO.File.Create(String path)
    at lambda_method(Closure )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any external library using which one can edit and save XML files
In my application I'm using an external library (Batik 1.7) that is made up
The object in the arraylist is defined in an external library. The object contains
I have an Android App which contains an external dependend jar library. This external
I have a C# class library that contains methods that need to be used
My application contains references to an external library (the SQL Server Management Objects). Apparently,
I have 2 projects: A Class Library that contains my classes/business logic A WPF
I have a class from an external library that I want to extend with
I have a C# class library that contains methods that need to be used
When including external library headers in my C++ project I can use -isystem flag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.