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

  • SEARCH
  • Home
  • 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 8414763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:14:54+00:00 2026-06-10T01:14:54+00:00

Could you please suggest work around for .NET 4.0 defect which results into Common

  • 0

Could you please suggest work around for .NET 4.0 defect which results into Common Language Runtime detected an invalid program. exception when following program is started (in Visual Studio 2010):

Note: Behavior does not reproduce when the same program is compiled in Visual Studion 2012.

namespace Namespace1
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    public class Tst1
    {
        public Action<DataType> Method1<DataType>(Func<DataType> param1) { return this.Method1<DataType>(param1, 0); }
        public Action<DataType> Method1<DataType>(Func<DataType> param1, int param2)
        {
            return param => System.Windows.Forms.MessageBox.Show(param1().ToString() + " " + param.ToString());
        }
    }

    public class TstBase { }

    public class Tst2 : TstBase { }

    public static class TstExtensions
    {
        public static string ExtensionMethod<TstType>(this TstType tst)
            where TstType : TstBase
        {
            return "From extension method";
        }
    }

    public class Application
    {
        public static void Main()
        {
            Tst1 tst1 = new Tst1();
            Tst2 tst2 = new Tst2();

            tst1.Method1<string>(tst2.ExtensionMethod)("From main");
        }
    }
}

Note: Assembly System.Windows.Forms.dll of .NET framework 4.0 needs to be referenced to build project.

Background information

I develop high-abstraction-level script-processing keyword-driven test automation framework upon low-level test automation tool shipped by 3-rd party (automation framework which performs keyword-driven scripts of high abstraction level with 3-rd party tool employed for accessing graphic UI on lower level). Construction listed above is required to implement uniform values validation approach.

Each element of listed code stand for following:

  • Tst1 – class for validation of values
  • Method1 – polymorphic method that performs validation of values which are being retrieved from UI (user interface) and can accept timeout to wait till UI element will acquire required value
  • TstBase – base class for all UI controls handling from 3-rd party low-level automation tool API
  • Tst2 – class for handling certain type of controls from 3-rd party low-level automation tool API
  • ExtensionMethod – generic method for retrieving text from controls of all types using instance of any control-handler-class from 3-rd party low-level automation tool API

Method1 returns delegate which is passed as argument to other method that retrieves value from test-script-step parameters and immediately makes use of it. Altogether it looks like following:

testStepParameters.MakeUseOf("Field1ExpectedValue", validation.Verify<string>(field1.GetValue));

where validation.Verify<string>(field1.GetValue) goes instead of tst1.Method1<string>(tst2.ExtensionMethod) from first-most code snippet.

Important notice

I found one work-around for the defect but I do not like it because it adds some extent of clumsiness to the code. Work around that I found is to replace direct usage of extension method with Lambda expression – i.e. bug does no reproduce when line:

tst1.Method1<string>(tst2.ExtensionMethod)("From main");

is replaced with line:

tst1.Method1<string>(() => tst2.ExtensionMethod())("From main");

In final form it looks like:

testStepParameters.MakeUseOf("Field1ExpectedValue", validation.Verify<string>(() => field1.GetValue()));

And usage of that work-around becomes completely unpleasant when instead of field1 variable is used a complicated call for retrieving control (probably a delegate returning control – which is especially useful to check control state over time without bothering about how control is retrieved – with its own implementation of GetValue extension method).

  • 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-10T01:14:56+00:00Added an answer on June 10, 2026 at 1:14 am

    You can fix it by creating the delegate yourself instead of letting C# do it for you. Like this:

     tst1.Method1<string>(new Func<string>(tst2.ExtensionMethod))("From main");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone please suggest a software process suitable to the work our team? We
Could someone please suggest why this is happening... I’ve got some code to pretty
I am very new to Ruby so could you please suggest the best practice
could somebody please take a look at this http://jsfiddle.net/bloodygeese/EzkFR/1/ My aim is to on
Can you please suggest me a mp3 jplayer link that would work in internet
I need to store phone numbers in a table. Please suggest which datatype should
Could someone please suggest a good way of taking a global seed value e.g.
Hi experts, can you please suggest me how can i start the work to
Wondering if someone could please explain the difference between these two queries and advise
I am missing something in my SQL query, could please someone advise how to

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.