Jump to content
  • Advertisement
Sign in to follow this  
Cygon

[.net] Are optional Assemblies possible?

This topic is 3040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to compile a project with an optional assembly reference?

For example, assume an assembly referenced nunit.framework.dll for its unit tests. During normal usage of the assembly, the unit tests (and thereby all code that accesses nunit.framework.dll) are not invoked at all.

Now I'd expect the assembly to be usable without nunit.framework.dll as long as the unit tests aren't called. However, as soon as I remove nunit.framework.dll from the output directory, the assembly can no longer be loaded due to missing references.

-

My guess is that normally it would work as I expect it to, just not with NUnit. Reason: nunit.framework.dll contains attributes (TestFixtureAttribute, TestAttribute, etc.) that need to be instantiated during load time.

Could that be it?

Share this post


Link to post
Share on other sites
Advertisement
Probably. I don't know if such a "delay load" of referenced assemblies is even possible, other than using a plugin logic, i.e. dynamically loading an assembly manually at runtime and use reflection to wire it.

But I can tell you how I "solved" this with my tests. Separate all your tests into a separate project, so your main app does not need to reference NUnit. The drawback being that you likely have to adjust some if not all tests if they for instance access internals, which is only possible from within the same assembly.

Share this post


Link to post
Share on other sites
Quote:
Original post by unbird
Probably. I don't know if such a "delay load" of referenced assemblies is even possible, other than using a plugin logic, i.e. dynamically loading an assembly manually at runtime and use reflection to wire it.

But I can tell you how I "solved" this with my tests. Separate all your tests into a separate project, so your main app does not need to reference NUnit. The drawback being that you likely have to adjust some if not all tests if they for instance access internals, which is only possible from within the same assembly.


Thanks, I already feared that I would have to take this path in the end. It's better for the end user, but I'll have to scroll up and down in Visual Studio's Solution Explorer whenever I want to find the unit tests of a class :)

The internals issue shouldn't be that much of a problem, there's always the InternalsVisibleTo attribute!

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

Share this post


Link to post
Share on other sites
That is my belief, too. But as soon as I delete nunit.framework.dll from my project's output folder it stops working with a System.IO.FileNotFoundException.

The unit test classes stay untouched during a normal run of my application, so I had expected that I could simply ship the application without nunit.framework.dll.

I've tried to reproduce the issue several times without success:

  • Application only references library: deleting library causes no problems

  • Application accesses library in unused method: no problems

  • Application uses attributes from library: no problems (!)

  • Application calls into library: exception at call site


Yet my production code fails as soon as the library in question is loaded unless nunit.framework.dll is in its directory. I simply get the "xyz has stopped working" dialog with no further details. If have enabled .NET's FusionLog, but it doesn't tell me where nunit.framework.dll was attempted to be loaded from. No callstack, no assembly...

Share this post


Link to post
Share on other sites
Seems I can learn something here! Put together a test and it seems to work: Crash is triggered only when actually calling NUnit (e.g. Assert.True()). You can even construct an attributed class without problems (!!). I checked then on a non-developer machine and still no problems.

How do you reference the assembly ? Through the GAC ? I've added NUnit manually, maybe that's a solution.

Still, yeah, those errors are very unhelpful. And even try/catching does not give back conclusive results (Edit:) does not catch them at all! Are they triggered by the runtime in a separate thread ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!