"Unable to create component" error - c#

I'm trying to develop a custom PDF viewer using PDFLibNet library.
I downloaded compiled dlls (32 and 64 bit) and took a look to examples: very nice.
Then I started a library project in VS2010 and created a new user control (the one I want to export): dll compiled succesfully.
So I created a GUI project (net 4.0), referenced my assembly and dropped my control to main form: I have an error that says (I'm translating, so it could be wrong) "Unable to create component 'PdfViewer'. Error message: 'System.IO:FileNotFoundException: unable to load file or assembly 'PDFLibNet, Version 1.0.6.8, .... or one of its dependencies. Unable to find specified file.".
To prevent some question:
Yes, my custom assembly references exactly that assembly
Yes, PDFLibNet assembly is exactly 1.0.6.8
In my control I tell to copy that DLL everytime
I tried to add PDFLibNet reference to GUI project, but I had the same error
Here is what I left after deleting everything (for testing purpose):
public partial class PdfViewer : UserControl
{
PDFWrapper _pdfDoc = null;
public PdfViewer()
{
InitializeComponent();
}
}
Just to tell you: if I try to remove any reference to PDFLibNet (removing PDFWrapper _pdfDoc = null;), my control is dropped correctly on form.
I even tried to register PDFLibNet into GAC, but the result is the same.
I'm really confused...

make sure you don't check debug folder and the output mode is release.

Related

How do I import my user control dll to my new project?

I have a user control project which contains a few controls I made myself. This project's output type is Class Library which produces a .dll file so I can import that in other projects. My problem here is when I rebuild the .dll project with Any CPU and import that dll to my second project I get this error:
An unhandled exception of type 'System.BadImageFormatException' occurred in SecondProject.exe
Additional information: Could not load file or assembly 'TestUserControlsDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567890abcdef' or one of its dependencies. An attempt was made to load a program with an incorrect format.
When I rebuild my dll project in 64bit I can see the user controls in design view but then I can't run my second project by clicking F5. This question is probably asked before but I'm at the point which I don't even know how to search about this problem.
What I try to do is import my dll output (user control project) into another project (which will be 64 bit) and be able to see the controls in design view and also able to run my project.
Problem solved..
I don't know how but creating a new dll project and just copy-paste my controls inside that new project under new namespace solved all of my problems. It's working now
take a look, at both target framework versions. (Project properties)
e.g. if your exe is 4.6.1 and your dll is 4.7.2, you get this error

Unable to load DLL in WPF C# application

I get following error message (VS2010) when running in debug mode my C# WPF appliction:
"Unable to load DLL 'VCECLB.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
The code where this error occurs is (see hDevEnum):
namespace Imperx.FLExGrabber
{
public class Enumerator:IEnumerator
{
private IntPtr hDevEnum;
VCECLB_EnumData enumData;
/// Default constructor
public Enumerator()
{
enumData.cbSize = (UInt32)Marshal.SizeOf(enumData);
// Open enumerator handle
hDevEnum = NativeFunctions.VCECLB_EnumInit(); <<--- Error message here!!!
}
/// Destructor
~Enumerator()
{
NativeFunctions.VCECLB_EnumClose(hDevEnum);
}
}
}
From the existing project, which uses a windows form application, it runs perfectly. Now I need to transfer this solution into a WPF-application. Therefore I am using the same machine (Win7/64ibt) with the same VS2010. The platform target is X64.
Question: Where I need to add the VCECLB.dll file into my project? I can not add it under references and therefore I put it into the folder "...\bin\x64\Release" - but no success.
When I check the VCECLB.dll with dependency walker I get following:
Does the question marks means that those dll's are missing? If so, why I can run the windows form project with the same VCECLB.dll?
Does anybody know how I can solve this issue?
Thanks in advance
There are two common causes for such an error:
The DLL that you are referring to is not on the DLL search path, or
The DLL that you are referring to is found, but its dependencies cannot be found.
Resolve problem 1 by putting the DLL in the same directory as the executable. Resolve problem 2 by making sure that all dependencies are installed. Typically this involves deploying the MSVC runtime that the DLL depends upon.
You can put your VCECLB.dll any where in your solution (in root for example by Drag & Drop)
Then, once you added the file, click right on your file, choose properties
In Advanced three:
Choose content in Build Action
And Always copy in Copy to output Directory
to get something like the follwing:

Lazy load a DLL that was placed on the filesystem after the program has been started

I am building an automation harness using C# and am trying to do the following:
Bootstrap the harness
Install the executable
Use a couple of DLLs that the executable lays down to establish a connection to the infrastructure that the exe connects to (large, complex software system)
The DLLs that I need to use are a few static classes that perform their own 'bootstrap' process to get connected to the rest of the servers in the test environment. What I have tried is creating a connection class that looks like this:
using CompanyName.Framework;
namespace TestNamespace{
public class ProductConnectorClass{
// Initialize a connection to the product and do stuff
public ProductConnectorClass(){
var connection = CompanyName.Framework.Initialize(...);
// Do stuff with the connection
connection.RunStuff();
}
}
}
The DLL that contains the CompanyName.Framework namespace is not accessible when the test framework is first started. It is copied via code from another class that looks lomething like this:
namespace TestNamespace{
public class TestRunnerClass{
public TestRunnerClass(){
// pseudo code here, so you get the idea:
CopyMsiToHost(msiRemotePath, msiLocalPath);
InstallMsi(msiLocalPath);
CopyDllsToTestHarnessDir();
ProductConnectorClass pcc = new ProductConnectorClass();
}
}
}
It is when the code hits the ProductConnectorClass pcc = new ProductConnectorClass(); line that I get an exception:
FileNotFoundException was unhandled
Could not load file or assembly 'CompanyName.Framework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX' or one of its dependencies. The system cannot find the file specified.
This puzzles me since I have set Specific Version: False on the DLL in my test project and I am operating under the assumption that .NET Lazy-loads DLLs (in my mind that means search for and load them at the time they are needed). At this point I am looking for a simple way to get a running .NET program to find a needed DLL that has been placed after the process started running.
Note 1: If I restart the process after the DLL is already in place, it loads fine. It looks like it is only scanning for DLLs on startup, which still puzzles me.
Note 2: This SO answer gives me some information about how DLLs are loaded, but doesn't fully answer my question. The synopsis is that if .NET has tried to load the DLL and it fails that it won't try to load it again. In my case I don't expect that a load attempt has been made on the DLL since the class where the DLL is referenced has not been instantiated yet.
From experiments in test projects that I have performed, it appears that I need to perform modularization of my code in order to get this to work. In no case am I able to reference a dll that does not currently exist, start my program then drop down the DLL.
Here are my steps to a solution:
Refactor my common classes and interfaces to their own DLL project in my Automation solution
Create another DLL project ('TestLogic') in my solution that uses the DLL I lay down after the program has started
When I need to use the DLL that is laid down after the program starts, I use reflection to load the TestLogic dll and perform the tests
For reference I did a google search for 'C# late load dll' and found this msdn social post with some helpful advice. Here is a copy/paste/modify of the most helpful reply from that thread:
Move all the code that references the DLLs that are installed after the test framework starts to a completely separate assembly. We'll call this "TestLogicAssembly".
Create a new assembly and define an interface. We'll call this "TestInterfaceAssembly".
Reference TestInterfaceAssembly in both your main DLL and your TestLogicAssembly.
Create a class in TestLogicAssembly that implements the interface created in TestInterfaceAssembly.
Don't reference TestLogicAssembly from your main application.
At runtime, check to see if the DLLs that are laid down as part of the install step of the test framework are actually installed. If they are, use Assembly.Load to load the TestLogicAssembly, then find the type that implements the interface defined in number 2. Use Activator.CreateInstance to create an instance of this type, and cast it to the interface you created.

Using lib in dll for c#

I have some problems with dll. When I make dll without using of lib files (which I need), everything is fine. But when I'm trying to use some functions in dll that uses functions in lib then some exception appears:
System.DllNotFoundException, cant load a dll module (exception from HRESULT:0x8007007E).
dll file is in correct place.
P.S. using Visual Studio 2010.
What could be wrong?
More detail in the question will get you better answers. But with current information, the most likely cause is that the lib file you are referencing or one of its dependencies is unavailable. This could be because it is not in your GAC or your runtime location, a file format conflict, or a number of other things.
I'm assuming that everything compiles without errors, of course. Again, please add detail if this is not what you need.
if you are making a new class you should reference the default dlls.
in example when you make a new class library and want to use a messagebox in your code ,
you should first reference that required dll in your program(i dont mean your dll,i mean dot net default dll like system.windows.forms) and then add using something; in the top of your class.
example : we want use messagebox in a class library then :
1. first from solution explorer right click the project > add reference ,now reference manager opens now from left tabs click assemblies then framework and then find and select system.windows.forms
2. now its time to use it in our program first add this line in very top of your class file
using System.Windows.Forms; //add this line in top of your class
after that we can use messagebox without any compiler errors.
keep in mind any other dll files should be referenced this way but in windows form applications default lib files are referenced by default

C# DLL run-time error - builds, runs, but throws unhandled exception upon trying to use DLL functions

I am trying to compile the example project shown here for C#. It had to be converted to VS2010, but that worked fine. It builds, runs, but then dies when it tries to access a DLL function.
I made a series of images to show my steps. As you can see, the device I designed is attached and correctly configured, but I really don't think that has anything to do with the issue. Inside the Form1.cs file, the following comment explains how to use the DLL:
/*
PLEASE NOTE
You must add a reference to the FTChipIDNet.dll in order to use this sample
To do this:
1. Click on Solution explorer tab.
2. Right click the References tree.
3. Choose Add Reference option.
4. Browse to the FTChipIDNet.dll (as a personal preference I place this in my bin directory)
5. Click OK
*/
I followed the instructions shown above and the undefined reference to the namespace FTChipID was fixed. I also manually checked the Object Browser to be sure the GetNumDevices function exists and it does.
Clicking the button produces this error:
DLLNotFoundException was unhandled:
Unable to load DLL 'FTChipID.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at this line of code:
FTChipID.ChipID.GetNumDevices(ref numDevices);
Now, you may be thinking "the error says it needs FTChipID.dll, not FTChipIDNet.dll." I'm wondering the same thing. I have FTChipID.dll along with a .lib and .h file, but I don't know how to use them or where they need to be in order for this program to find them. I tried adding a reference to FTChipID.dll, but VS2010 said
A reference to ...\FTChipID.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
I don't know what that means either. Any ideas? Thanks in advance.
FTChipIDNet.dll is a wrapper for the FTChipID.dll, so you need to add the reference to your solution (as you did above) and then copy the FTChipID.dll to the bin folder there FTChipIDNet.dll will be located.
Both dll's should be located in your solution's bin folder to operate and should not be located in windows\system32.
I built the FTDI sample program "CSChipID" in VS2013 using a build to "Any CPU". The two DLL files "FTChipID.dll" and "FTChipIDNet.dll" were copied to the bin directory, but I continued to get errors when the first DLL function was called, "FTChipID.ChipID.GetNumDevices(ref numDevices);" The fix is change the build to "x86" as follows.
Build - Configuration Manager
Active Solution Platform - "x86"
Note: If "x86" is not available, select -New...- to select "x86".
It sounds like there are multiple .dll's: both FTChipIDNet.dll (the one you interface to), and FTChipID.dll (the one with the actual, non-COM, non-.Net functionality). You need both.
SUGGESTION: Copy both to your \windows\system32 directory

Categories

Resources