Add dll to project

Hi Experts,

I have a dll of required classes written in C#. I want to use these classes in my project. When I try to add the dll as a reference I am told the file is not a .Net module. How can I add them?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you sure its a C# DLL? What are the .NET versions of DLL and your project?
Jorge SanchezSoftware EngineerCommented:
If it's not a .Net Module maybe it's a library of C++. In this case you must import individual functions using DLLImport
Miguel OzSenior Software EngineerCommented:
You have to check that the dll is a .net C# class library. Easy way to check is to use reflector and open the dll.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

DColinAuthor Commented:
Hi Experts,

The dll is a C# class library.

The attached code snippet is of the class TwoPlayerTrueSkillCalculator. How do I use DllImport to use this class in my VB.Net project I have added Imports System.Runtime.InteropServices to my project.

using System;
using System.Collections.Generic;
using System.Linq;
using Moserware.Skills.Numerics;

namespace Moserware.Skills.TrueSkill
    /// <summary>
    /// Calculates the new ratings for only two players.
    /// </summary>
    /// <remarks>
    /// When you only have two players, a lot of the math simplifies. The main purpose of this class
    /// is to show the bare minimum of what a TrueSkill implementation should have.
    /// </remarks>
    public class TwoPlayerTrueSkillCalculator : SkillCalculator
        public TwoPlayerTrueSkillCalculator()
            : base(SupportedOptions.None, Range<TeamsRange>.Exactly(2), Range<PlayersRange>.Exactly(1))

        /// <inheritdoc/>
        public override IDictionary<TPlayer, Rating> CalculateNewRatings<TPlayer>(GameInfo gameInfo,
                                                                                      <IDictionary<TPlayer, Rating>>
                                                                                      teams, params int[] teamRanks)
            // Basic argument checking
            Guard.ArgumentNotNull(gameInfo, "gameInfo");

            // Make sure things are in order
            RankSorter.Sort(ref teams, ref teamRanks);

            // Get the teams as a list to make it easier to index
            List<IDictionary<TPlayer, Rating>> teamList = teams.ToList();

            // Since we verified that each team has one player, we know the player is the first one
            IDictionary<TPlayer, Rating> winningTeam = teamList[0];
            TPlayer winner = winningTeam.Keys.First();
            Rating winnerPreviousRating = winningTeam[winner];

            IDictionary<TPlayer, Rating> losingTeam = teamList[1];
            TPlayer loser = losingTeam.Keys.First();
            Rating loserPreviousRating = losingTeam[loser];

            bool wasDraw = (teamRanks[0] == teamRanks[1]);

            var results = new Dictionary<TPlayer, Rating>();
            results[winner] = CalculateNewRating(gameInfo, winnerPreviousRating, loserPreviousRating,
                                                 wasDraw ? PairwiseComparison.Draw : PairwiseComparison.Win);
            results[loser] = CalculateNewRating(gameInfo, loserPreviousRating, winnerPreviousRating,
                                                wasDraw ? PairwiseComparison.Draw : PairwiseComparison.Lose);

            // And we're done!
            return results;

        private static Rating CalculateNewRating(GameInfo gameInfo, Rating selfRating, Rating opponentRating,
                                                 PairwiseComparison comparison)
            double drawMargin = DrawMargin.GetDrawMarginFromDrawProbability(gameInfo.DrawProbability, gameInfo.Beta);

            double c =

            double winningMean = selfRating.Mean;
            double losingMean = opponentRating.Mean;

            switch (comparison)
                case PairwiseComparison.Win:
                case PairwiseComparison.Draw:
                    // NOP
                case PairwiseComparison.Lose:
                    winningMean = opponentRating.Mean;
                    losingMean = selfRating.Mean;

            double meanDelta = winningMean - losingMean;

            double v;
            double w;
            double rankMultiplier;

            if (comparison != PairwiseComparison.Draw)
                // non-draw case
                v = TruncatedGaussianCorrectionFunctions.VExceedsMargin(meanDelta, drawMargin, c);
                w = TruncatedGaussianCorrectionFunctions.WExceedsMargin(meanDelta, drawMargin, c);
                rankMultiplier = (int) comparison;
                v = TruncatedGaussianCorrectionFunctions.VWithinMargin(meanDelta, drawMargin, c);
                w = TruncatedGaussianCorrectionFunctions.WWithinMargin(meanDelta, drawMargin, c);
                rankMultiplier = 1;

            double meanMultiplier = (Square(selfRating.StandardDeviation) + Square(gameInfo.DynamicsFactor))/c;

            double varianceWithDynamics = Square(selfRating.StandardDeviation) + Square(gameInfo.DynamicsFactor);
            double stdDevMultiplier = varianceWithDynamics/Square(c);

            double newMean = selfRating.Mean + (rankMultiplier*meanMultiplier*v);
            double newStdDev = Math.Sqrt(varianceWithDynamics*(1 - w*stdDevMultiplier));

            return new Rating(newMean, newStdDev);

        /// <inheritdoc/>
        public override double CalculateMatchQuality<TPlayer>(GameInfo gameInfo,
                                                              IEnumerable<IDictionary<TPlayer, Rating>> teams)
            Guard.ArgumentNotNull(gameInfo, "gameInfo");

            Rating player1Rating = teams.First().Values.First();
            Rating player2Rating = teams.Last().Values.First();

            // We just use equation 4.1 found on page 8 of the TrueSkill 2006 paper:
            double betaSquared = Square(gameInfo.Beta);
            double player1SigmaSquared = Square(player1Rating.StandardDeviation);
            double player2SigmaSquared = Square(player2Rating.StandardDeviation);

            // This is the square root part of the equation:
            double sqrtPart =
                    (2*betaSquared + player1SigmaSquared + player2SigmaSquared));

            // This is the exponent part of the equation:
            double expPart =
                    (-1*Square(player1Rating.Mean - player2Rating.Mean))
                    (2*(2*betaSquared + player1SigmaSquared + player2SigmaSquared)));

            return sqrtPart*expPart;

Open in new window

What are the .NET versions of DLL and your project? Also, show us a screenshot of the AddReference window where the file is being listed and show us the screenshot of error itself.

DColinAuthor Commented:
Hi CodeCruiser:

This screenshot shows the Add Reference dialogue box listing the Moserware.Skills.dll and it's location, but when I add the dll to my project's  References it is showing it can not be found (see attached). I am able to add this dll to my C# projects but not VB
DColinAuthor Commented:
Here is the image as a file add reference
DColinAuthor Commented:
I can not get the image to expand I hope you can.
What was the issue and how did you get it working?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.