admin管理员组文章数量:1391947
Using C#, .NET 9 and I have added the nuget package for System.Data.Oledb
I have included using System.Data.Oledb
The file System.Data.Oledb.dll
is in the same folder as the exe.
When I launch the exe in debug mode (debugger attached) everything works.
When I launch the same exe without debugger I get the error
Could not load file or assembly 'System.Data.OleDb, Version=9.0.0.3, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Why can't it find the assembly without debugger attached?
Note: I'm running in EXCATLY the same location - just with the debugger or without the debugger.
Using C#, .NET 9 and I have added the nuget package for System.Data.Oledb
I have included using System.Data.Oledb
The file System.Data.Oledb.dll
is in the same folder as the exe.
When I launch the exe in debug mode (debugger attached) everything works.
When I launch the same exe without debugger I get the error
Could not load file or assembly 'System.Data.OleDb, Version=9.0.0.3, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Why can't it find the assembly without debugger attached?
Note: I'm running in EXCATLY the same location - just with the debugger or without the debugger.
Share Improve this question edited Mar 13 at 23:55 Michael T asked Mar 13 at 23:24 Michael TMichael T 7918 silver badges23 bronze badges 5- Did you ensure that System.Data.OleDb.dll is copied to the output directory? If yes, then If your app is not running in a development environment, dependencies may be missing on the target machine. Considering your answer I may figure it out. – Emad Kerhily Commented Mar 13 at 23:51
- @EmadKerhily I've updated my question to make it clear I'm launching the app from the same location each time. – Michael T Commented Mar 13 at 23:57
- Let's try my answer and test some solutions step by step – Emad Kerhily Commented Mar 14 at 0:10
- 1 @EmadKerhily Thanks your answer explicitly loading the assembly at runtime combined with this stackoverflow/questions/79164448/… helped me figure it out. The build process now copies the specific files from the runtimes subfolder. But I have no idea why it worked under debug mode. – Michael T Commented Mar 14 at 1:07
- Because, when you run in debug mode, Visual Studio ensures dependencies are loaded – Emad Kerhily Commented Mar 14 at 1:20
1 Answer
Reset to default 1Even though you have System.Data.OleDb.dll
in the same folder, it’s worth ensuring it's copied correctly during build.
Modify your .csproj
file to always copy the DLL to the output:
<ItemGroup>
<None Update="System.Data.OleDb.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
clean and rebuild the project and let me know if it works.
Alternatively, you can load assembly at runtime explicitly in your program.cs:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
if (args.Name.Contains("System.Data.OleDb"))
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System.Data.OleDb.dll");
return File.Exists(path) ? Assembly.LoadFrom(path) : null;
}
return null;
};
本文标签: cCould not load file or assembly 39SystemDataOleDb39 without debuggerStack Overflow
版权声明:本文标题:c# - Could not load file or assembly 'System.Data.OleDb' without debugger - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744679931a2619340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论