DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Problems with .Net 2.0 Mixed Mode Assemblies inside Visual Studio .Net 4.5 Test Projects

Problems with .Net 2.0 Mixed Mode Assemblies inside Visual Studio .Net 4.5 Test Projects

Douglas Rathbone user avatar by
Douglas Rathbone
·
Sep. 17, 12 · Interview
Like (0)
Save
Tweet
Share
3.47K Views

Join the DZone community and get the full member experience.

Join For Free

when you include .net 2.0 mixed mode assemblies in .net 4.0 or .net 4.5 projects you often have to add some start up options to your project’s config file to get it all to play nice when your app starts up. this backwards compatibility feature is great as it allow you to use older/non supported projects in your recent work. when when using visual studio 2012’s new unit testing tools this magical piece of app.config code doesn’t seem to help though, and the solution is pretty simple.

image recently i’ve had great fun working on some green field .net 4.5 projects. while unit testing some of the code in these projects using visual studio’s “super sweet” async testing tools i’ve come across a niggling little issue that breaks with normal convention when it comes to testing code that depends on older assemblies.

the problem

normally when you are loading .net 2.0 assemblies as a reference into a .net 4.0 or 4.5 project you have to tell .net that it should run in a compatibility mode so that your old assembly will load properly.

this is because .net 2, 3.0 and 3.5 assemblies are all built against the .net 2.0 clr.

.net 4.0 and 4.5 assemblies are built against different clr’s and therefore startup differently.

for backwards compatibility the microsoft .net teams kindly allowed you the add the following to your web.config or app.config to make this all still work:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup uselegacyv2runtimeactivationpolicy="true">
    <supportedruntime version="v4.0" sku=".netframework,version=v4.5" />
    <supportedruntime version="v2.0.50727"></supportedruntime>
  </startup>
</configuration>

the above will make your application run fine when placed into the app’s config file.

when writing unit tests against a .net 4.0 or 4.5 assembly and running these unit tests inside visual studio 2012 this fix sadly doesn’t work.

case in point with my sharpsvn “bang my head against a brick wall” exception below which worked when running in my app, but failed under unit test (the be fair this is an integration test – apologies to the unit testing elitists out there…):

image

the solution

the reason the normal app.config fix doesn’t work when using the microsoft test runner built into visual studio 2012 is that the test runner’s environment isn’t inside your test project’s bin folder . it’s running somewhere else.

the file you need to place your compatibility config settings in is:

c:\program files (x86)\microsoft visual studio 11.0\common7\ide\commonextensions\microsoft\testwindow\vstest.executionengine86.exe.config


if you open the above file using your favourite notepad (running as administrator) and place the same “startup” section mentioned higher in this post inside this file, all your problems resolve themselves.

hopefully the above post can save you the time it took me to find it.

unit test Assembly (CLI)

Published at DZone with permission of Douglas Rathbone, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top 10 Secure Coding Practices Every Developer Should Know
  • Load Balancing Pattern
  • Better Performance and Security by Monitoring Logs, Metrics, and More
  • OpenID Connect Flows

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: