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 7978039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:22:52+00:00 2026-06-04T09:22:52+00:00

The EndToEnd test of my application includes loading the releasedlls by hand. During testing

  • 0

The EndToEnd test of my application includes loading the releasedlls by hand.

During testing i always have the following loaded:
– NUnit shadowcopy of n debug assemblies
– Postbuildeventcopy of n release assemblies

Even if i am sure that the two copies are from the same build generation (version) casting of my reflection loading fails.

to give a little bit of context here is some pseudo code:

private HookingHelper globalhooker;
private Tools.ISomething globalmockery;


TestfixtureSetUp(){
    globalhooker = new globalhooker();
    globalhooker.Loadfrom("c:\postbuildcopy.dll");
    globalmockery = Mockrepository.Generate<Tools.ISomething>();
    globalhooker.SetViaReflection<Tools.ISomething>("nameofsomething", globalmockery);
 }

I have a helper class which uses Loadfrom to get a static inside an assembly. Before i call anything i have to inject a mock.

This mock is created using the shadowcopy of a tools library in debug version since nunit creates it.

The loaded library is the release version, which is important to me since i want to do testing as close to the real environment as possible.

When i try to inject using reflection i have to use FieldInfo SetValue(...) the call looks something like this:

    public static void ReplaceFieldPublicStatic<T>(Type type, string fieldname, T obj)
    {
        FieldInfo field = AssemblyHelper.GetFieldInfoPublicStatic(type, fieldname);
        field.SetValue((T)obj, obj);
    }

Somethimes the Reflection works and sometimes my types can not be casted into each other.

The error is an ArgumentException generated by FieldInfo SetValue(...) .

When i inercept the exception and investigate the difference between field.FieldType != typeof(T) only the GetHashCode() call gives a different value.

I think there is a little bit of randomness involved.

Can i force the Typecast? Is that even wise?

Is there something i need to do while buildung my projects that i am missing?

  • 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-04T09:22:53+00:00Added an answer on June 4, 2026 at 9:22 am

    Even if i am sure that the two copies are from the same build generation (version) casting of my reflection loading fails.

    Yes – if two types have come from two different Assembly objects, they are different types as far as the CLR is concerned. The assemblies could have been loaded from the exact same byte sequences, but they’re still distinct assemblies.

    Basically you’ll need to pick one Assembly to use for each type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: ( Live demo here - Open in Internet Explorer 7
When I click on a link in my test, it opens a new tab.
I am trying to get the caret position for some text inside an iframe

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.