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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:33:24+00:00 2026-05-24T12:33:24+00:00

i have a method registered like this: [DllImport(MyApi.dll, CharSet = CharSet.Ansi)] private static extern

  • 0

i have a method registered like this:

    [DllImport("MyApi.dll", CharSet = CharSet.Ansi)]
    private static extern int SomeRandomCall();

and i added the MyApi.dll to the project with “Copy always = true” and locally everything compiles fine and the MSTest Unittests are working…

But: When i try to run the unittests manually via console, like:

mstest.exe /testcontainer:C:\mytestdll.dll

the tests are failing and that’s because mstest ( which finally executes the tests in my dll ) expects the MyApi.dll to be in its directory ( C:\Windows[…]\IDE 7\MSTest.exe )… Ok, makes sense, but:

As C# attributes require constant values as parameters, i can not use sth. like “GetCurDir() + “MyApi.dll”…
What is the best solution to handle this “dynamic path to MyApi.dll” problem?

The only thing i can think of right now is conditional compiler symbols, but that’s pretty dirty…

  • 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-05-24T12:33:25+00:00Added an answer on May 24, 2026 at 12:33 pm

    The DllImport is fine as it is; what you need to do is make sure the library loader can find MyApi.dll at runtime. One way to accomplish this is with the PATH environment variable:

    set PATH=%PATH%;C:\
    
    mstest.exe /testcontainer:C:\mytestdll.dll
    

    …assuming MyApi.dll is in C:\ (not recommended).

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

Sidebar

Related Questions

I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
I have a plugin which defines a callback setter like this: extern C __declspec(dllexport)
I have some MSVC++ compiled DLL's for which I have created COM-like (lite) interfaces
I have some relatively large legacy method that I would like to refactor. It
Problem with validation I would have run the validation when the method registered In
We have a database library in C# that we can use like this: DatabaseConnection
I have an expression like this Expression<Func<IInterface, object>> How do i loop/traverse through all
I have an NSView subclass which registers for drag files in init method like
hi i have a problem with the parsecontrol() method Control c = this.ParseControl(<uc1:GroupListControl NickName='HARD'
I have a problem with Codeigniter routes. I would like to all registered users

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.