C
C#3y ago
Elio

DLL Unable to load file or assembly [Answered]

Hi, i've made my own DLL and when i try to create a new variable with a class from this DLL, it launch the following error : 'System.IO.FileNotFoundException' an error occurred in System.Windows.Forms.dll Unable to load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and if i remove the new variable this error disappear and my program goes running, have you any idea why this following error occur ?
16 Replies
Elio
ElioOP3y ago
to add more details, i use the following package in the DLL maybe i forgot to include this package while generating my dll but i'm not sure
Elio
ElioOP3y ago
Elio
ElioOP3y ago
here an example of my code :
using Communication;
using Communication.Beckhoff;

namespace TestCommunicationV5
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
CommunicationBeckhoff test = new CommunicationBeckhoff();
}
}
using Communication;
using Communication.Beckhoff;

namespace TestCommunicationV5
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
CommunicationBeckhoff test = new CommunicationBeckhoff();
}
}
If i comment the line with test the program work ...
cyan_live
cyan_live3y ago
Try adding reference System.Runtime to the project or nuget: https://www.nuget.org/packages/System.Runtime/
Elio
ElioOP3y ago
it didn't work :/
Klarth
Klarth3y ago
What kind of app is running your library/DLL and what runtime does it use?
Elio
ElioOP3y ago
It is just some class which use io port to make method for communicate with an electronic card and it use the last version of runtime I guess
Klarth
Klarth3y ago
Don't guess. The error is potentially about a version mismatch because it should ship with one of the apps. Are the main program and this library in the same VS solution using project references? Or are you trying some other way to create this?
Elio
ElioOP3y ago
Nop they aren't I've created them yesterday so that why I said it should be the last version for both I've created a the library yesterday and the winforms today and I e implemented the library to the winforms
Klarth
Klarth3y ago
Are they in two separate solutions? If so, do they have reason to be?
Elio
ElioOP3y ago
Yes they are, there is no particular reason just in the first solution there is my library and other project and i've created a win form only to test de library
Klarth
Klarth3y ago
So keeping them in separate solutions makes things harder because you need to either: 1. manually transfer the DLL and all required components to the main project build or 2. publish as a NuGet package and setup a local NuGet server.
Elio
ElioOP3y ago
Ok so I will put them in the same solution it will be easier then
Klarth
Klarth3y ago
Whereas if you have them in the same solution...you right click the main project in VS: Add -> Project Reference. Then click your library. The build system will then know exactly what other dependencies might be required (without going the NuGet package route).
Elio
ElioOP3y ago
Thanks it work now 😁 I will take note of this
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server