Visual Studio not copying dependencies | Could not load file or assembly












1















I'm writing a class library to abstract our company's Database functions, but when the code gets to instantiating one of my database objects we get a:




FileNotFound Exception:



Could not load file or assembly 'MySql.Data,
Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or
one of its dependencies. The system cannot find the file specified.




The MySql.Data Dependencies as stated on the website are:





  • .NETStandard 2.0 Google.Protobuf (>= 3.5.1)

  • System.Configuration.ConfigurationManager (>= 4.4.1)

  • System.Security.Permissions (>= 4.4.1)

  • System.Text.Encoding.CodePages (>= 4.4.0)




But all of them are installed automatically.




  • The NuGet package is MySql.Data (8.0.13) (which installs successfully)

  • Project is a .NET Standard 2.0 class library

  • There are no compile errors or even warnings; just the above error at run-time.


Have looked through Could not load file or assembly or one of its dependencies which advises checking where the dependencies are not being found - so I did - but it doesn't say how to fix the missing reference when you've found where it is?



Using Process Monitor I was able to find the failed CreateFile operation DLL calls, referencing ...TestingGUIbinDebugMySql.DataMySql.Data.dll which, manually checking, is not there.



The project that runs is a WinForms app that references another .NET Standard class library (essentially a middleman) which then references the database library which depends on MySql.Data.



Doing a search in the whole solution directory, there are no MySql.Data.dll files, especially after a full solution build.



Here is my csproj file



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>App1.Database</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
</ItemGroup>

</Project>


So, who's a .NET Wizard?



UPDATE:



So it turns out the code works fine when run from a .Net Core console app, but only has the error when referenced from a .NET app (specifically winforms). So I've given up having a GUI for now and am just using a .NET Core console app. I thought .NET Standard was compatible with everything, but maybe not? Anyway, I will keep my question here for anyone else having troubles.



UPDATE 2:



Thanks to @Itay Podhajcer's answer we managed to get it working with .NET Winforms by also including the NuGet package there.










share|improve this question

























  • Can you update your question to include your csproj file?

    – Scott Chamberlain
    Nov 14 '18 at 5:10











  • Can you try uninstall and reinstall MySql.Data (8.0.13) ?

    – hsyn.ozkara
    Nov 14 '18 at 8:20











  • is the problem there when you try to run it from the studio or when you try to execute the .exe on another computer?

    – Thomas
    Nov 14 '18 at 9:58











  • @ScottChamberlain uploading csproj now

    – Moffen
    Nov 14 '18 at 19:06











  • @hsyn.ozkara have tried that a few times and even from the command line

    – Moffen
    Nov 14 '18 at 19:06
















1















I'm writing a class library to abstract our company's Database functions, but when the code gets to instantiating one of my database objects we get a:




FileNotFound Exception:



Could not load file or assembly 'MySql.Data,
Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or
one of its dependencies. The system cannot find the file specified.




The MySql.Data Dependencies as stated on the website are:





  • .NETStandard 2.0 Google.Protobuf (>= 3.5.1)

  • System.Configuration.ConfigurationManager (>= 4.4.1)

  • System.Security.Permissions (>= 4.4.1)

  • System.Text.Encoding.CodePages (>= 4.4.0)




But all of them are installed automatically.




  • The NuGet package is MySql.Data (8.0.13) (which installs successfully)

  • Project is a .NET Standard 2.0 class library

  • There are no compile errors or even warnings; just the above error at run-time.


Have looked through Could not load file or assembly or one of its dependencies which advises checking where the dependencies are not being found - so I did - but it doesn't say how to fix the missing reference when you've found where it is?



Using Process Monitor I was able to find the failed CreateFile operation DLL calls, referencing ...TestingGUIbinDebugMySql.DataMySql.Data.dll which, manually checking, is not there.



The project that runs is a WinForms app that references another .NET Standard class library (essentially a middleman) which then references the database library which depends on MySql.Data.



Doing a search in the whole solution directory, there are no MySql.Data.dll files, especially after a full solution build.



Here is my csproj file



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>App1.Database</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
</ItemGroup>

</Project>


So, who's a .NET Wizard?



UPDATE:



So it turns out the code works fine when run from a .Net Core console app, but only has the error when referenced from a .NET app (specifically winforms). So I've given up having a GUI for now and am just using a .NET Core console app. I thought .NET Standard was compatible with everything, but maybe not? Anyway, I will keep my question here for anyone else having troubles.



UPDATE 2:



Thanks to @Itay Podhajcer's answer we managed to get it working with .NET Winforms by also including the NuGet package there.










share|improve this question

























  • Can you update your question to include your csproj file?

    – Scott Chamberlain
    Nov 14 '18 at 5:10











  • Can you try uninstall and reinstall MySql.Data (8.0.13) ?

    – hsyn.ozkara
    Nov 14 '18 at 8:20











  • is the problem there when you try to run it from the studio or when you try to execute the .exe on another computer?

    – Thomas
    Nov 14 '18 at 9:58











  • @ScottChamberlain uploading csproj now

    – Moffen
    Nov 14 '18 at 19:06











  • @hsyn.ozkara have tried that a few times and even from the command line

    – Moffen
    Nov 14 '18 at 19:06














1












1








1








I'm writing a class library to abstract our company's Database functions, but when the code gets to instantiating one of my database objects we get a:




FileNotFound Exception:



Could not load file or assembly 'MySql.Data,
Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or
one of its dependencies. The system cannot find the file specified.




The MySql.Data Dependencies as stated on the website are:





  • .NETStandard 2.0 Google.Protobuf (>= 3.5.1)

  • System.Configuration.ConfigurationManager (>= 4.4.1)

  • System.Security.Permissions (>= 4.4.1)

  • System.Text.Encoding.CodePages (>= 4.4.0)




But all of them are installed automatically.




  • The NuGet package is MySql.Data (8.0.13) (which installs successfully)

  • Project is a .NET Standard 2.0 class library

  • There are no compile errors or even warnings; just the above error at run-time.


Have looked through Could not load file or assembly or one of its dependencies which advises checking where the dependencies are not being found - so I did - but it doesn't say how to fix the missing reference when you've found where it is?



Using Process Monitor I was able to find the failed CreateFile operation DLL calls, referencing ...TestingGUIbinDebugMySql.DataMySql.Data.dll which, manually checking, is not there.



The project that runs is a WinForms app that references another .NET Standard class library (essentially a middleman) which then references the database library which depends on MySql.Data.



Doing a search in the whole solution directory, there are no MySql.Data.dll files, especially after a full solution build.



Here is my csproj file



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>App1.Database</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
</ItemGroup>

</Project>


So, who's a .NET Wizard?



UPDATE:



So it turns out the code works fine when run from a .Net Core console app, but only has the error when referenced from a .NET app (specifically winforms). So I've given up having a GUI for now and am just using a .NET Core console app. I thought .NET Standard was compatible with everything, but maybe not? Anyway, I will keep my question here for anyone else having troubles.



UPDATE 2:



Thanks to @Itay Podhajcer's answer we managed to get it working with .NET Winforms by also including the NuGet package there.










share|improve this question
















I'm writing a class library to abstract our company's Database functions, but when the code gets to instantiating one of my database objects we get a:




FileNotFound Exception:



Could not load file or assembly 'MySql.Data,
Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or
one of its dependencies. The system cannot find the file specified.




The MySql.Data Dependencies as stated on the website are:





  • .NETStandard 2.0 Google.Protobuf (>= 3.5.1)

  • System.Configuration.ConfigurationManager (>= 4.4.1)

  • System.Security.Permissions (>= 4.4.1)

  • System.Text.Encoding.CodePages (>= 4.4.0)




But all of them are installed automatically.




  • The NuGet package is MySql.Data (8.0.13) (which installs successfully)

  • Project is a .NET Standard 2.0 class library

  • There are no compile errors or even warnings; just the above error at run-time.


Have looked through Could not load file or assembly or one of its dependencies which advises checking where the dependencies are not being found - so I did - but it doesn't say how to fix the missing reference when you've found where it is?



Using Process Monitor I was able to find the failed CreateFile operation DLL calls, referencing ...TestingGUIbinDebugMySql.DataMySql.Data.dll which, manually checking, is not there.



The project that runs is a WinForms app that references another .NET Standard class library (essentially a middleman) which then references the database library which depends on MySql.Data.



Doing a search in the whole solution directory, there are no MySql.Data.dll files, especially after a full solution build.



Here is my csproj file



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>App1.Database</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
</ItemGroup>

</Project>


So, who's a .NET Wizard?



UPDATE:



So it turns out the code works fine when run from a .Net Core console app, but only has the error when referenced from a .NET app (specifically winforms). So I've given up having a GUI for now and am just using a .NET Core console app. I thought .NET Standard was compatible with everything, but maybe not? Anyway, I will keep my question here for anyone else having troubles.



UPDATE 2:



Thanks to @Itay Podhajcer's answer we managed to get it working with .NET Winforms by also including the NuGet package there.







c# .net visual-studio nuget .net-standard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 20:56







Moffen

















asked Nov 14 '18 at 4:55









MoffenMoffen

775217




775217













  • Can you update your question to include your csproj file?

    – Scott Chamberlain
    Nov 14 '18 at 5:10











  • Can you try uninstall and reinstall MySql.Data (8.0.13) ?

    – hsyn.ozkara
    Nov 14 '18 at 8:20











  • is the problem there when you try to run it from the studio or when you try to execute the .exe on another computer?

    – Thomas
    Nov 14 '18 at 9:58











  • @ScottChamberlain uploading csproj now

    – Moffen
    Nov 14 '18 at 19:06











  • @hsyn.ozkara have tried that a few times and even from the command line

    – Moffen
    Nov 14 '18 at 19:06



















  • Can you update your question to include your csproj file?

    – Scott Chamberlain
    Nov 14 '18 at 5:10











  • Can you try uninstall and reinstall MySql.Data (8.0.13) ?

    – hsyn.ozkara
    Nov 14 '18 at 8:20











  • is the problem there when you try to run it from the studio or when you try to execute the .exe on another computer?

    – Thomas
    Nov 14 '18 at 9:58











  • @ScottChamberlain uploading csproj now

    – Moffen
    Nov 14 '18 at 19:06











  • @hsyn.ozkara have tried that a few times and even from the command line

    – Moffen
    Nov 14 '18 at 19:06

















Can you update your question to include your csproj file?

– Scott Chamberlain
Nov 14 '18 at 5:10





Can you update your question to include your csproj file?

– Scott Chamberlain
Nov 14 '18 at 5:10













Can you try uninstall and reinstall MySql.Data (8.0.13) ?

– hsyn.ozkara
Nov 14 '18 at 8:20





Can you try uninstall and reinstall MySql.Data (8.0.13) ?

– hsyn.ozkara
Nov 14 '18 at 8:20













is the problem there when you try to run it from the studio or when you try to execute the .exe on another computer?

– Thomas
Nov 14 '18 at 9:58





is the problem there when you try to run it from the studio or when you try to execute the .exe on another computer?

– Thomas
Nov 14 '18 at 9:58













@ScottChamberlain uploading csproj now

– Moffen
Nov 14 '18 at 19:06





@ScottChamberlain uploading csproj now

– Moffen
Nov 14 '18 at 19:06













@hsyn.ozkara have tried that a few times and even from the command line

– Moffen
Nov 14 '18 at 19:06





@hsyn.ozkara have tried that a few times and even from the command line

– Moffen
Nov 14 '18 at 19:06












2 Answers
2






active

oldest

votes


















2














I remember encountering the same issue, I think it was related to the new nuget referencing model.
Try adding the missing nuget package directly to the WinForms project.Far from ideal solution, but it should work.



Hope it helps!






share|improve this answer
























  • Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

    – Moffen
    Nov 14 '18 at 20:54








  • 1





    netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

    – Itay Podhajcer
    Nov 14 '18 at 20:58



















0















Visual Studio not copying dependencies | Could not load file or assembly




It seems the dependencies and assembly are not copied to the output folder. You can check the thread for some more details:



PackageReference is missing copy files to output feature



To resolve this issue, you can try to following workaround:



<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>


Hope this helps.






share|improve this answer
























  • Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

    – Moffen
    Nov 14 '18 at 19:07











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293402%2fvisual-studio-not-copying-dependencies-could-not-load-file-or-assembly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I remember encountering the same issue, I think it was related to the new nuget referencing model.
Try adding the missing nuget package directly to the WinForms project.Far from ideal solution, but it should work.



Hope it helps!






share|improve this answer
























  • Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

    – Moffen
    Nov 14 '18 at 20:54








  • 1





    netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

    – Itay Podhajcer
    Nov 14 '18 at 20:58
















2














I remember encountering the same issue, I think it was related to the new nuget referencing model.
Try adding the missing nuget package directly to the WinForms project.Far from ideal solution, but it should work.



Hope it helps!






share|improve this answer
























  • Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

    – Moffen
    Nov 14 '18 at 20:54








  • 1





    netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

    – Itay Podhajcer
    Nov 14 '18 at 20:58














2












2








2







I remember encountering the same issue, I think it was related to the new nuget referencing model.
Try adding the missing nuget package directly to the WinForms project.Far from ideal solution, but it should work.



Hope it helps!






share|improve this answer













I remember encountering the same issue, I think it was related to the new nuget referencing model.
Try adding the missing nuget package directly to the WinForms project.Far from ideal solution, but it should work.



Hope it helps!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 20:13









Itay PodhajcerItay Podhajcer

1,9491412




1,9491412













  • Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

    – Moffen
    Nov 14 '18 at 20:54








  • 1





    netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

    – Itay Podhajcer
    Nov 14 '18 at 20:58



















  • Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

    – Moffen
    Nov 14 '18 at 20:54








  • 1





    netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

    – Itay Podhajcer
    Nov 14 '18 at 20:58

















Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

– Moffen
Nov 14 '18 at 20:54







Not ideal but you're right, it works! You'd think visual studio would pass its references down, maybe it's a bug. Thankyou!!

– Moffen
Nov 14 '18 at 20:54






1




1





netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

– Itay Podhajcer
Nov 14 '18 at 20:58





netstandart is the new stuff, but not everything works smoothly with it, net core 3.0 should solve some of the problems, but for that will need to wait and see.

– Itay Podhajcer
Nov 14 '18 at 20:58













0















Visual Studio not copying dependencies | Could not load file or assembly




It seems the dependencies and assembly are not copied to the output folder. You can check the thread for some more details:



PackageReference is missing copy files to output feature



To resolve this issue, you can try to following workaround:



<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>


Hope this helps.






share|improve this answer
























  • Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

    – Moffen
    Nov 14 '18 at 19:07
















0















Visual Studio not copying dependencies | Could not load file or assembly




It seems the dependencies and assembly are not copied to the output folder. You can check the thread for some more details:



PackageReference is missing copy files to output feature



To resolve this issue, you can try to following workaround:



<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>


Hope this helps.






share|improve this answer
























  • Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

    – Moffen
    Nov 14 '18 at 19:07














0












0








0








Visual Studio not copying dependencies | Could not load file or assembly




It seems the dependencies and assembly are not copied to the output folder. You can check the thread for some more details:



PackageReference is missing copy files to output feature



To resolve this issue, you can try to following workaround:



<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>


Hope this helps.






share|improve this answer














Visual Studio not copying dependencies | Could not load file or assembly




It seems the dependencies and assembly are not copied to the output folder. You can check the thread for some more details:



PackageReference is missing copy files to output feature



To resolve this issue, you can try to following workaround:



<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>


Hope this helps.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 9:42









Leo Liu-MSFTLeo Liu-MSFT

18.8k22232




18.8k22232













  • Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

    – Moffen
    Nov 14 '18 at 19:07



















  • Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

    – Moffen
    Nov 14 '18 at 19:07

















Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

– Moffen
Nov 14 '18 at 19:07





Have tried <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> but that didn't help either :(

– Moffen
Nov 14 '18 at 19:07


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293402%2fvisual-studio-not-copying-dependencies-could-not-load-file-or-assembly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python