Ошибка cs0006 не удалось найти файл метаданных dll

I know there is another question with exact the same problem, but I went trough all those answers, and none helped me. :( (This was the question.)

I just created a new ASP.NET MVC project and joined a few ‘.dll’s in the solution. Now when I try to build the project I get the error message shown below on 3 of the 5 libraries.

Error   CS0006  Metadata file 'C:\Users\...\source\Database\bin\Debug\DataAccessLayer.dll' could not be found   Logic   C:\Users\...\source\Logic\CSC   1   Active

Error   CS0006  Metadata file 'C:\Users\...\source\Logic\bin\Debug\Logic.dll' could not be found    PTS2-MVC    C:\Users\...\source\PTS2-MVC\CSC    1   Active

Error   CS0006  Metadata file 'C:\Users\...\source\PTS2-MVC\bin\PTS2-MVC.dll' could not be found    PTS2-MVC.Tests  C:\Users\...\source\PTS2-MVC.Tests\CSC  1   Active

When I go to the bin\debug folder of that .dll, I see that it is empty, and the other .dll where I do not get an error message, is not empty. But I am clueless how to fix this or what I did to make this happen.

The most common answer is to go to the properties of the solution and go to configuration and uncheck -> apply -> check and apply again, but that didn’t work

JYelton's user avatar

JYelton

35.7k27 gold badges133 silver badges191 bronze badges

asked May 29, 2017 at 22:37

Svenmarim's user avatar

9

The problem was that I had some other normal error messages in my project, and apparently after I fixed those and when I cleaned and built my project AGAIN, then all .dlls succeeded.

Make sure you don’t have any other error messages in your project and if you do, fix those first!

Félix Adriyel Gagnon-Grenier's user avatar

answered May 30, 2017 at 9:15

Svenmarim's user avatar

SvenmarimSvenmarim

3,6435 gold badges24 silver badges56 bronze badges

14

Steps in Fixing this Error: MetaData File .dll could not be found.

  1. Clean All Projects.

  2. Unload All Projects.

  3. Reload All Projects.

  4. ReBuild Solution.

Then problem solved.

answered Oct 27, 2017 at 5:46

rjay dadula's user avatar

rjay dadularjay dadula

5904 silver badges3 bronze badges

3

In my case, there was an error, but it was not properly parsed out by VS and shown in the «Error List» window. To find it, you much view the ol «Output» from build window and parse through the messages starting from top down and resolve the actual error. M$, please fix! This is a huge waste of time of the worlds collective developers.

answered Jan 18, 2018 at 7:34

ebol2000's user avatar

ebol2000ebol2000

1,20512 silver badges16 bronze badges

1

Double check the name of your project folder. In my case my project folder was named with spaces in it. When I cloned the project from Team Foundation Server using git bash the spaces in the folder name were converted to: «%20». Changing those back to spaces fixed the problem for me.

answered Dec 12, 2017 at 21:17

roscoelee's user avatar

roscoeleeroscoelee

1711 silver badge5 bronze badges

3

I had this issue with a solution containing multiple projects.

It came from duplicating a .csproj and adding the copy to the solution. A .csproj file contains a <ProjectGuid> element. I set the GUID of the copied project to a new one.

Update: Which GUID you use doesn’t matter, it just needs to be different from the other project’s GUID. You can create a new GUID from within Visual Studio: Tools -> Create GUID and copy the part between the curly brackets, i.e. {...}. Use that as the new value for the <ProjectGuid> element.

I also performed the following steps (not neccessarily neccessary, but they don’t hurt):

  1. Close the solution
  2. Delete bin folder
  3. Delete all obj folders
  4. Open solution and build

answered Dec 20, 2017 at 9:49

j00hi's user avatar

j00hij00hi

5,4303 gold badges45 silver badges82 bronze badges

0

I fix this problem following this steps:

  1. Clean Solution
  2. Close Visual Studio
  3. Deleting /bin from the project directory
  4. Restart Visual Studio
  5. Rebuild Solution

answered Aug 20, 2018 at 14:33

Lucas Prestes's user avatar

Lucas PrestesLucas Prestes

3621 gold badge4 silver badges19 bronze badges

1

Another thing that you should check is the Target Framework of any referenced projects to make sure that the calling project is using the same or later version of the framework.

I had this issue, I tried all of the previously suggested answers and then on a hunch checked the frameworks. One of projects being referenced was targeting 4.6.1 when the calling project was only 4.5.2.

answered Jan 12, 2018 at 0:39

Rob's user avatar

RobRob

511 silver badge3 bronze badges

1

For me cleaning and building didn’t work. Unloading the project didn’t work. Restarting Visual Studio or even the pc didn’t work. This is what did work:

Go to each of the projects that are throwing the error, and in References, delete the reference to the problematic project and add it again. That solves the issue.

The problem seems to be related to moving a project around (Move it inside a folder for example), then a different project that references it, have its path wrong and can’t find it.

answered Aug 30, 2018 at 14:57

David Perez's user avatar

David PerezDavid Perez

4785 silver badges17 bronze badges

1

I had the same problem, even with no other errors showing on the «Error List» view after «Rebuild Solution». However, on the «Output» view, I saw the error that was behind the issue:

The primary reference «C:…\myproj.dll» could not be resolved because it was built against the «.NETFramework,Version=v4.6.1» framework. This is a higher version than the currently targeted framework «.NETFramework,Version=v4.5»

Once I corrected this, the issue was resolved.

answered Oct 2, 2018 at 9:04

Ian's user avatar

I have the same problem, the problem was that solution path have spaces in the name and vs for some reason not resolve the package… download my repository again just renaming the solution with out spaces in the name.

e.g:

/Repo/Project Name/src

should be

/Repo/ProjectName/src

JonathanDavidArndt's user avatar

answered Jan 13, 2018 at 17:30

D__'s user avatar

D__D__

1411 silver badge5 bronze badges

1

What worked for me:

Package Manager Console (Visual Studio 2019 Comunity):

Install-Package NuGet.CommandLine
nuget locals all -clear

Rebuild solution.

answered Aug 28, 2019 at 9:31

s3c's user avatar

s3cs3c

1,48119 silver badges28 bronze badges

I have build 10 projects out of 25 projects in solution individually one by one based on dependencies. Then build the solution. It fixed for me

answered Jan 12, 2020 at 17:17

Siva Sankaran's user avatar

Siva SankaranSiva Sankaran

1,5214 gold badges21 silver badges40 bronze badges

1

Running this command in bash to delete all bins worked for me

$ find . -iname "bin" -o -iname "obj" | xargs rm -rf

Can’t guarantee it’ll work for anyone else though

Also be aware it’ll delete all bin files -so you will have to rebuild all projects. Obviously best to cd into the relevant directory before using it.

answered Feb 20, 2018 at 17:16

Yair Halberstadt's user avatar

Cleaning my solution caused this problem with Visual Studio 2017. Unloading/reloading projects or more cleaning made no difference. Only thing that worked was closing and restarting Visual Studio.

answered Mar 21, 2018 at 20:20

John81's user avatar

John81John81

3,7366 gold badges38 silver badges58 bronze badges

1

Check all the projects are loaded. In my case one of the project was unloaded and reloading the project clears the errors.

answered Jun 26, 2018 at 5:13

Maryam's user avatar

MaryamMaryam

1,4174 gold badges19 silver badges33 bronze badges

In my case, I had to open the .csproj file and add the reference by hand, like this (Microsoft.Extensions.Identity.Stores.dll was missing):

<Reference Include="Microsoft.Extensions.Identity.Stores">
  <HintPath>..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.identity.stores\2.0.1\lib\netstandard2.0\Microsoft.Extensions.Identity.Stores.dll</HintPath>
</Reference>

answered Oct 4, 2018 at 19:28

toutecrimson's user avatar

Close Visual Studio, find the solution’s .suo file, delete it, reopen Visual Studio.

answered Mar 7, 2019 at 15:18

Graham Laight's user avatar

Graham LaightGraham Laight

4,7003 gold badges30 silver badges28 bronze badges

I had the same problem and i tried solutions from
Metadata file ‘.dll’ could not be found

but none of these worked.

So after trial and error i fixed it by unloading and reloading the project doing this reset the configuration file and fixed the issue.

answered May 30, 2019 at 6:33

Amad Malik's user avatar

In my case I was facing same error. One of my project solution was referring an assembly from different NuGet location. I just changed it to correct location to solve this error and rebuild. and wow the project get build successfully and all other error gone away.

answered Feb 5, 2018 at 14:30

Mukesh Kumar's user avatar

I had this same error. In my case I had built a library (call it commsLibrary) that referenced other libraries by including them as projects in my solution. Later, when I built a project and added my commsLibrary, whenever I would build I got the metadata file cannot be found error. So I added the libraries that my comms library referenced to the current project, then it was able to build.

answered Jun 26, 2018 at 21:52

Joseph Mawer's user avatar

After facing so many troubles, here is the solution that I found.

  1. open your project folder.
  2. find Your_Project_Name.csproj[Visual C# Project file (.csproj)]
  3. open that file in any text editor and find your missing file ItemGroup.

    <ItemGroup>
    <None Include="..." />
    </ItemGroup>

  4. remove that ItemGroup and open once again your project and build

  5. If that reference is important for you then add once again.

rptwsthi's user avatar

rptwsthi

10.1k10 gold badges68 silver badges109 bronze badges

answered Dec 20, 2018 at 7:10

Abhishek Shingadiya's user avatar

I had the same issue. My problem was someone else on the team moved a class folder, and the project was looking for it.

For me, there were 44 errors; 43 ended in .dll (searching for a dependency) and the first one in the error list ended with .cs (searching for the actual class). I tried clean-build, and clean, unload, reload, build, but nothing working. I ended up locating the class in the project, and just deleted it, as it was showing up as unavailable anyways, followed by a clean-build.

That did the trick for me! Hope this helps.

answered Feb 22, 2019 at 13:57

Burke's user avatar

I had 2 files (and 2 classes) in the same project with the same name.

answered Mar 20, 2019 at 19:33

JohnB's user avatar

JohnBJohnB

18.1k16 gold badges98 silver badges110 bronze badges

In my case, I deleted one file directly from team explorer git menu which was causing this problem. When I checked solution explorer it was still showing the deleted file as unreferenced file. When I removed that file from solution explorer, I was able to build project successfully.

answered Apr 10, 2019 at 3:43

p4ulinux's user avatar

p4ulinuxp4ulinux

3295 silver badges14 bronze badges

For me what worked was:

Uninstall and then reinstall the referenced Nuget package that has the error.

answered May 28, 2019 at 18:51

Andrew's user avatar

AndrewAndrew

18.8k13 gold badges104 silver badges118 bronze badges

In my case I run the tests and got error CS0006. It turned out that I run tests in Release mode. Switch to Debug mode fixed this error.

answered Jun 24, 2019 at 11:38

izimiky's user avatar

izimikyizimiky

991 silver badge3 bronze badges

This issue happens when you renamed your solution and the .net framework cannot find the old solution.

To resolve this, you need to find and replace the old name of solution and all dependencies on it with the new name. If you need to browse the physical file through file explorer do so.

The files that are normally affected are AssemblyInfo.cs, .sln an Properties > Application > Assembly name and Default namespace. Make sure to update them with the new name.

Open the file explorer, if the folder with the old name still exists, you need to delete it. Then clean and build the solution until the error is gone. (If needed clean and build the project one by one especially the affected project.)

Matthew's user avatar

Matthew

1,9053 gold badges19 silver badges26 bronze badges

answered Mar 26, 2018 at 3:34

John Carlo Diocadiz's user avatar

In my case the issue was, I was referencing a project where I commented out all the .cs files.

For example ProjectApp references ProjectUtility. In ProjectUtility I only had 1 .cs file. I wasn’t using it anymore so I commented out the whole file. In ProjectApp I wasn’t calling any of the code from ProjectUtility, but I had using ProjectUtility; in one of the ProjectApp .cs files. The only error I got from the compiler was the CS0006 error.

I uncommented the .cs file in ProjectUtility and the error went away. So I’m not sure if having no code in a project causes the compiler to create an invalid assembly or not generate the DLL at all. The fix for me was to just remove the reference to ProjectUtility rather than commenting all the code.

In case you were wondering why I commented all the code from the referenced project instead of removing the reference, I did it because I was testing something and didn’t want to modify the ProjectApp.csproj file.

answered Nov 8, 2019 at 16:24

iheartcsharp's user avatar

iheartcsharpiheartcsharp

1,2791 gold badge14 silver badges22 bronze badges

After working through a couple of issues in dependent projects, like the accepted answer says, I was still getting this error. I could see the file did indeed exist at the location it was looking in, but for some reason Visual Studio would not recognize it. Rebuilding the solution would clear all dependent projects and then would not rebuild them, but building individually would generate the .dll’s. I used msbuild <project-name>.csproj in the developer PowerShell terminal in Visual Studio, meaning to get some more detailed debugging information—but it built for me instead! Try using msbuild against persistant build errors; you can use the --verbosity: option to get more output, as outlined in the docs.

answered Feb 26, 2021 at 20:49

NerdyGinger's user avatar

NerdyGingerNerdyGinger

4067 silver badges13 bronze badges

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32;
 
namespace CPlan.W3LF
{
    /// <summary>
    /// The wrapper around W3L.
    /// </summary>
    public static class Loader
    {
 
        #region API
        /// <summary>
        /// The call that is made to W3L.dll.
        /// </summary>
        /// <param name="CommandLine">Command line arguments. <remarks>Add the full execution path in quotation.</remarks></param>
        /// <param name="ExePath">The path to war3.exe.</param>
        /// <param name="ErrorMsg">Any error message that occured while patching/loading war3.exe.</param>
        /// <returns>A code about how the library has handled the call.</returns>
        [DllImport("w3l.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        static extern int DoInject(string CommandLine, string ExePath, [Out] out string ErrorMsg);
        // UNDONE: Changed the size of the API definition.
        //static extern Int32 DoInject(
        //    [MarshalAs(UnmanagedType.LPStr)] string CommandLine,
        //    [MarshalAs(UnmanagedType.LPStr)] string ExePath,
        //    [Out][MarshalAs(UnmanagedType.LPStr)] out string ErrorMsg
        //    );
        #endregion
        /// <summary>
        /// A list of Warcraft III startup options.
        /// </summary>
        [Flags]
        public enum StartOptions : byte
        {
            /// <summary>
            /// No special arguments.
            /// </summary>
            None = 0,
            /// <summary>
            /// Starts Warcraft III in windowed mode.
            /// </summary>
            Window = 1,
            /// <summary>
            /// Starts Warcraft III with OpenGL.
            /// </summary>
            OpenGl = 2,
            /// <summary>
            /// Starts Warcraft III with Software Transform and Lighting Video mode
            /// </summary>
            SWTNL = 4,
            /// <summary>
            /// Starts classic Warcraft III.
            /// </summary>
            Classic = 8
        }
        /// <summary>
        /// List for the registry check.
        /// </summary>
        private static List<Gateway> gateways = new List<Gateway>() { 
            new Gateway(new Uri("server.eurobattle.net"), 8, "Eurobattle.Net"),
            new Gateway(new Uri("localhost"), 8, "Eurobattle.Net GProxy")
        };
 
        /// <summary>
        /// Attempts to start Warcraft III (and GProxy.)
        /// </summary>        
        /// <returns>True if call(s) has/have succeeded; else false.</returns>
#if XPAM
        /// <param name="RunGP">Determine whether or not to check data for GProxy as well.</param>
        public static bool RunW3(bool RunGP)
#else
        public static bool RunW3()
#endif
        {
            try
            {
                // Check if war3.exe and w3lh.dll exist.
                try
                {
                    if (!File.Exists(Path.Combine(Settings.W3Path, "war3.exe")))
                    {
                        MessageBox.Show("The given directory does not contain war3.exe, please make sure your registry contains the right information.\r\n\r\nPath: " + Settings.W3Path, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    if (!File.Exists(Path.Combine(Settings.W3Path + "w3lh.dll")))
                    {
                        if (File.Exists(Path.Combine(Environment.CurrentDirectory + "w3lh.dll")))
                        {
                            File.Copy(Path.Combine(Environment.CurrentDirectory + "w3lh.dll"), Path.Combine(Settings.W3Path + "w3lh.dll"));
                        }
                        else
                        {
                            MessageBox.Show("w3lh.dll copy in the directory \"" + Environment.CurrentDirectory + "\\w3lh.dll\" does not exist.\r\nPlease reinstall EuroLoader.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show("The application does not have the rights to either read or write to the source/destination directory.", "Error", MessageBoxButtons.OK);
                    return false;
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("w3lh.dll was not found, please reinstall the application.", "Error", MessageBoxButtons.OK);
                    return false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An unhandled exception was thrown.\r\n\r\n" + ex.Message, "Error", MessageBoxButtons.OK);
                    return false;
                }
                // Checks the registry for a server.eurobattle.net entry.
                List<string> Entries = new List<string>((string[])Registry.CurrentUser.OpenSubKey("Software\\Blizzard Entertainment\\Warcraft III").GetValue("Battle.net Gateways"));
                //int count = (Entries.Count - 2) / 3;
                int server = 0;
                bool hasServer = false;
                for (int i = 2; i < Entries.Count; i += 3)
                {
                    if (!hasServer) ++server;
                    foreach (Gateway gw in gateways)
                    {
                        if (Entries[i].Equals(gw.Hostname.ToString()) || Entries[i + 2].Equals(gw.Name))
                        {
                            if (!Entries[i].Equals(gw.Hostname.ToString())) Entries[i + 1] = gw.Hostname.ToString();
                            if (!Entries[i + 1].Equals(gw.TimeZone)) Entries[i + 1] = gw.TimeZone.ToString();
                            if (!Entries[i + 2].Equals(gw.Name)) Entries[i + 1] = gw.Name;
                            hasServer = true;
                        }
                    }
                }
                Entries[1] = (server.ToString().Length == 2 ? server.ToString() : "0" + server.ToString());
                Registry.CurrentUser.OpenSubKey("Software\\Blizzard Entertainment\\Warcraft III", true).SetValue("Battle.net Gateways", Entries.ToArray(), RegistryValueKind.MultiString);
                // Checks for the given arguments.
                StartOptions StartOption = Settings.StartupOptions;
                string Args = "";
                if ((StartOption & StartOptions.Window) == StartOptions.Window) Args += " -window ";
                if ((StartOption & StartOptions.OpenGl) == StartOptions.OpenGl) Args += " -opengl ";
                if ((StartOption & StartOptions.SWTNL) == StartOptions.SWTNL) Args += " -swtnl ";
                if ((StartOption & StartOptions.Classic) == StartOptions.Classic) Args += " -classic ";
                string Msg;
                /*
                 * Why Settings.W3Path + "\\war3.exe":
                 *  The command line will not accept one argument.
                 *  Structure:
                 *      <Path of the to-execute application> [arguments]
                 *  If you do:
                 *      -window
                 *  Windows/Warcraft III will think you're starting up -window with no arguments.
                 *  Therefore you must have at least two arguments.
                 */
                switch (DoInject('"' + Path.Combine(Settings.W3Path, "war3.exe") + '"' + Args, Path.Combine(Settings.W3Path, "war3.exe"), out Msg))
                {
                    case 0: if (Msg != null) MessageBox.Show(Msg, "Startup message"); return true; // No error.
                    case 2: MessageBox.Show("Unable to find war3.exe in\r\n" + Msg, "Error", MessageBoxButtons.OK); return false;
                    case 1:
                    default: MessageBox.Show(Msg, "Error", MessageBoxButtons.OK); return false;
                }
            }
            catch (AccessViolationException)
            {
                MessageBox.Show("An exception was thrown: Access Violation.", "Error", MessageBoxButtons.OK);
                return false;
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show("Loader was unable to find w3l.dll.\r\nReinstalling the application could solve the issue.", "Error", MessageBoxButtons.OK);
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("An exception was thrown:\r\n\r\n" + ex.Message, "Error", MessageBoxButtons.OK);
                return false;
            }
        }
    }
}

Well, my answer is not just the summary of all the solutions, but it offers more than that.

Section (1):

In general solutions:

I had four errors of this kind (‘metadata file could not be found’) along with one error saying ‘Source File Could Not Be Opened (‘Unspecified error ‘)’.

I tried to get rid of ‘metadata file could not be found’ error. For that, I read many posts, blogs, etc. and found these solutions may be effective (summarizing them over here):

  1. Restart Visual Studio and try building again.

  2. Go to ‘Solution Explorer’. Right click on Solution. Go to Properties. Go to ‘Configuration Manager’. Check if the checkboxes under ‘Build’ are checked or not. If any or all of them are unchecked, then check them and try building again.

  3. If the above solution(s) do not work, then follow sequence mentioned in step 2 above, and even if all the checkboxes are checked, uncheck them, check again and try to build again.

  4. Build Order and Project Dependencies:

    Go to ‘Solution Explorer’. Right click on Solution. Go to ‘Project Dependencies…’. You will see two tabs: ‘Dependencies’ and ‘Build Order’. This build order is the one in which solution builds. Check the project dependencies and the build order to verify if some project (say ‘project1’) which is dependent on other (say ‘project2’) is trying to build before that one (project2). This might be the cause for the error.

  5. Check the path of the missing .dll:

    Check the path of the missing .dll. If the path contains space or any other invalid path character, remove it and try building again.

    If this is the cause, then adjust the build order.


Section (2):

My particular case:

I tried all the steps above with various permutations and combinations with restarting Visual Studio a few times. But, it did not help me.

So, I decided to get rid of other error I was coming across (‘Source File Could Not Be Opened (‘Unspecified error ‘)’).

I came across a blog post: TFS Error–Source File Could Not Be Opened (‘Unspecified error ‘)

I tried the steps mentioned in that blog post, and I got rid of the error ‘Source File Could Not Be Opened (‘Unspecified error ‘)’ and surprisingly I got rid of other errors (‘metadata file could not be found’) as well.


Section (3):

Moral of the story:

Try all solutions as mentioned in section (1) above (and any other solutions) for getting rid of the error. If nothing works out, as per the blog mentioned in section (2) above, delete the entries of all source files which are no longer present in the source control and the file system from your .csproj file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32;
 
namespace CPlan.W3LF
{
    /// <summary>
    /// The wrapper around W3L.
    /// </summary>
    public static class Loader
    {
 
        #region API
        /// <summary>
        /// The call that is made to W3L.dll.
        /// </summary>
        /// <param name="CommandLine">Command line arguments. <remarks>Add the full execution path in quotation.</remarks></param>
        /// <param name="ExePath">The path to war3.exe.</param>
        /// <param name="ErrorMsg">Any error message that occured while patching/loading war3.exe.</param>
        /// <returns>A code about how the library has handled the call.</returns>
        [DllImport("w3l.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        static extern int DoInject(string CommandLine, string ExePath, [Out] out string ErrorMsg);
        // UNDONE: Changed the size of the API definition.
        //static extern Int32 DoInject(
        //    [MarshalAs(UnmanagedType.LPStr)] string CommandLine,
        //    [MarshalAs(UnmanagedType.LPStr)] string ExePath,
        //    [Out][MarshalAs(UnmanagedType.LPStr)] out string ErrorMsg
        //    );
        #endregion
        /// <summary>
        /// A list of Warcraft III startup options.
        /// </summary>
        [Flags]
        public enum StartOptions : byte
        {
            /// <summary>
            /// No special arguments.
            /// </summary>
            None = 0,
            /// <summary>
            /// Starts Warcraft III in windowed mode.
            /// </summary>
            Window = 1,
            /// <summary>
            /// Starts Warcraft III with OpenGL.
            /// </summary>
            OpenGl = 2,
            /// <summary>
            /// Starts Warcraft III with Software Transform and Lighting Video mode
            /// </summary>
            SWTNL = 4,
            /// <summary>
            /// Starts classic Warcraft III.
            /// </summary>
            Classic = 8
        }
        /// <summary>
        /// List for the registry check.
        /// </summary>
        private static List<Gateway> gateways = new List<Gateway>() { 
            new Gateway(new Uri("server.eurobattle.net"), 8, "Eurobattle.Net"),
            new Gateway(new Uri("localhost"), 8, "Eurobattle.Net GProxy")
        };
 
        /// <summary>
        /// Attempts to start Warcraft III (and GProxy.)
        /// </summary>        
        /// <returns>True if call(s) has/have succeeded; else false.</returns>
#if XPAM
        /// <param name="RunGP">Determine whether or not to check data for GProxy as well.</param>
        public static bool RunW3(bool RunGP)
#else
        public static bool RunW3()
#endif
        {
            try
            {
                // Check if war3.exe and w3lh.dll exist.
                try
                {
                    if (!File.Exists(Path.Combine(Settings.W3Path, "war3.exe")))
                    {
                        MessageBox.Show("The given directory does not contain war3.exe, please make sure your registry contains the right information.rnrnPath: " + Settings.W3Path, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    if (!File.Exists(Path.Combine(Settings.W3Path + "w3lh.dll")))
                    {
                        if (File.Exists(Path.Combine(Environment.CurrentDirectory + "w3lh.dll")))
                        {
                            File.Copy(Path.Combine(Environment.CurrentDirectory + "w3lh.dll"), Path.Combine(Settings.W3Path + "w3lh.dll"));
                        }
                        else
                        {
                            MessageBox.Show("w3lh.dll copy in the directory "" + Environment.CurrentDirectory + "\w3lh.dll" does not exist.rnPlease reinstall EuroLoader.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show("The application does not have the rights to either read or write to the source/destination directory.", "Error", MessageBoxButtons.OK);
                    return false;
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("w3lh.dll was not found, please reinstall the application.", "Error", MessageBoxButtons.OK);
                    return false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An unhandled exception was thrown.rnrn" + ex.Message, "Error", MessageBoxButtons.OK);
                    return false;
                }
                // Checks the registry for a server.eurobattle.net entry.
                List<string> Entries = new List<string>((string[])Registry.CurrentUser.OpenSubKey("Software\Blizzard Entertainment\Warcraft III").GetValue("Battle.net Gateways"));
                //int count = (Entries.Count - 2) / 3;
                int server = 0;
                bool hasServer = false;
                for (int i = 2; i < Entries.Count; i += 3)
                {
                    if (!hasServer) ++server;
                    foreach (Gateway gw in gateways)
                    {
                        if (Entries[i].Equals(gw.Hostname.ToString()) || Entries[i + 2].Equals(gw.Name))
                        {
                            if (!Entries[i].Equals(gw.Hostname.ToString())) Entries[i + 1] = gw.Hostname.ToString();
                            if (!Entries[i + 1].Equals(gw.TimeZone)) Entries[i + 1] = gw.TimeZone.ToString();
                            if (!Entries[i + 2].Equals(gw.Name)) Entries[i + 1] = gw.Name;
                            hasServer = true;
                        }
                    }
                }
                Entries[1] = (server.ToString().Length == 2 ? server.ToString() : "0" + server.ToString());
                Registry.CurrentUser.OpenSubKey("Software\Blizzard Entertainment\Warcraft III", true).SetValue("Battle.net Gateways", Entries.ToArray(), RegistryValueKind.MultiString);
                // Checks for the given arguments.
                StartOptions StartOption = Settings.StartupOptions;
                string Args = "";
                if ((StartOption & StartOptions.Window) == StartOptions.Window) Args += " -window ";
                if ((StartOption & StartOptions.OpenGl) == StartOptions.OpenGl) Args += " -opengl ";
                if ((StartOption & StartOptions.SWTNL) == StartOptions.SWTNL) Args += " -swtnl ";
                if ((StartOption & StartOptions.Classic) == StartOptions.Classic) Args += " -classic ";
                string Msg;
                /*
                 * Why Settings.W3Path + "\war3.exe":
                 *  The command line will not accept one argument.
                 *  Structure:
                 *      <Path of the to-execute application> [arguments]
                 *  If you do:
                 *      -window
                 *  Windows/Warcraft III will think you're starting up -window with no arguments.
                 *  Therefore you must have at least two arguments.
                 */
                switch (DoInject('"' + Path.Combine(Settings.W3Path, "war3.exe") + '"' + Args, Path.Combine(Settings.W3Path, "war3.exe"), out Msg))
                {
                    case 0: if (Msg != null) MessageBox.Show(Msg, "Startup message"); return true; // No error.
                    case 2: MessageBox.Show("Unable to find war3.exe inrn" + Msg, "Error", MessageBoxButtons.OK); return false;
                    case 1:
                    default: MessageBox.Show(Msg, "Error", MessageBoxButtons.OK); return false;
                }
            }
            catch (AccessViolationException)
            {
                MessageBox.Show("An exception was thrown: Access Violation.", "Error", MessageBoxButtons.OK);
                return false;
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show("Loader was unable to find w3l.dll.rnReinstalling the application could solve the issue.", "Error", MessageBoxButtons.OK);
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("An exception was thrown:rnrn" + ex.Message, "Error", MessageBoxButtons.OK);
                return false;
            }
        }
    }
}

I am trying to add two new test projects to my solution. When I add them and add references, the build initially creates the dll’s in the debug folder. when I build or rebuild again, it is always empty and I have a
Error CS0006 Metadata file .dll’ could not be found error. I’ve checked the build configuration manager and the boxes are checked to have it output to the debug folder. I’ve tried clean, build, rebuild on the solution, I’ve made sure there were no other left-over projects laying around and deleted them. I’m not sure what else I can do to get it to build and output the dll’s..

asked Sep 21, 2016 at 3:06

stacv's user avatar

1

I had similar issue.
Problem started when I canceled compilation manually.

To solve it, I started compiling projects one by one. Reading output of compilation allowed to spot the root project that was not compiled. That root project had an error. And somehow that error was not reported, looks like due to canceling compilation manually.

I went to that root project, fixed the error. Compiled it only that project. Then compiled the whole solution. And it got fixed.

answered Nov 22, 2021 at 12:39

user's user avatar

useruser

411 silver badge5 bronze badges

I fixed this by adding the target project as a dependency.

Right-click on the Solution in Solution Explorer, select Project Dependencies, choose a test project, and select the project from which the dll is built.

answered Nov 3, 2016 at 15:51

Michael Mainer's user avatar

Michael MainerMichael Mainer

3,3331 gold badge13 silver badges31 bronze badges

I got the same error message.

I referenced core class library (netcore) to core (xproj) application.

Problem was, that I had changed by manual editing in the xproj project, the output path:

to

<OutputPath Condition="'$(OutputPath)'=='' ">..bin</OutputPath>

but my xproj application had:

<OutputPath Condition="'$(OutputPath)'=='' ">.bin</OutputPath>

Changing to the same output path helped.

answered Sep 26, 2016 at 13:47

Motlicek Petr's user avatar

Check if the .nuget directory is complete.

File names:

-NuGet.Config
-NuGet.exe
-NuGet.targets
-packages.config

In my case NuGet.exe was missing from the branch, because when I check in on TFS, it does not send NuGet.exe.

techdreams's user avatar

techdreams

5,2937 gold badges42 silver badges63 bronze badges

answered Jan 24, 2017 at 5:58

Ilysamo's user avatar

1

I got a similar error. It turned out to be an issue with the database migrations. Unfortunately, I could not fix the issue.

My solution was to delete the migrations and the DB. When I added migrations again, everything was working. It should be possible to delete the migrations from the Db as well as from the .net migrations folder and then treat the project as database first. There is likely a better solution though, and I don’t know that I would try the above with real data at stake.

answered Apr 25, 2022 at 12:41

SakerCobalt's user avatar

1

Понравилась статья? Поделить с друзьями:

Интересное по теме:

  • Ошибка cs0004 pubg на ps4 решение
  • Ошибка cs 0004 пабг пс4
  • Ошибка cryptopro уц не является доверенным
  • Ошибка crystal process died
  • Ошибка crysis 3 msvcr100 dll

  • Добавить комментарий

    ;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: