I am trying to create a dll using X#. I started a Class Library project. Since I need to use a 3rd party (EZTwain) product, the first thing I did was to import their class by adding eztwain.cs to my project as instructed by their guide.
Eztwain.cs' namespace is "Atalasoft.EZTwain". In my class I added "USING Atalasoft.EZTwain".
It failed to compile. The error is "The type or namespace name 'Atalasoft' could not be found (are you missing a using directive or an assembly reference?)".
Here is my class that will be consuming EZTwain:
BEGIN NAMESPACE QLScan
public method MethodA() as void
I also tried changing the namespace in eztwain.cs to match my project namespace. In this case the compiler doesn't like "EZTwain.EndMultipageFile()".
In C# I didn't have any issue with using eztwain.cs. I already created a C# Windows form project to test the functionality of EZTwain. I also started a Class Library project in C# and added eztwain.cs. No compilation issue.
Unfortunately, I cannot add reference to their dll in both C# and X# projects. The error I received when attempting to add reference to their dll is:
Could not load file or assembly 'Eztwain4.dll or one of its dependencies. The module was expected to contain an assembly mainifest.
Does eztwain.cs need to be converted to X# in order to use it in X# project?
I tried "Using Atalasoft ". I also changed the namespace in eztwain.cs to "Atalasoft". Still have same compile error.
Attached is the screen shot of my simple C# dll project solution explorer. When I received the compile error in X#, I was wondering if I would also get the same error in C#. So this C# dll project was created to help me.
Attachment not found
In case the attachment isn't clear, there are only two classes in this project. They are class1.cs and eztwain.cs. The references are the standard one that Microsoft inserted with the exception of "System.Drawing", which is needed by eztwain.cs.
Here is my entire code of my class1.cs:
public class Class1
public void MethodA()
No compile issue. The line "EZTwain.EndMultipageFile();" was there to see if I can access EZTwain properties/methods.
Here are the first few lines from eztwain.cs:
public abstract class EZTwain
/// Gets the EZImage as .Net image object.
/// <returns>.Net image object.</returns>
public static System.Drawing.Image DIB_ToImage(System.IntPtr hdib)
My intent is to create a dll using X# and use my C# windows form project as a guide since I got it working. Once I create the dll, I plan to create a windows services to consume it using X# as well. Once again, I would use my current C# windows services project as a guide.
Are you sure that you can't mix X# and C#? Sometime last year when I was playing with X#, I was able to insert a .cs file to my X# project and reference the C# properties and methods in the .prg file. Base on this experience I decided to import eztwain.cs to my current X# project. If this has changed, then I have to rethink about using X# for this project since I need to use a 3rd party product.
I suspect the problem is related to having a class name and a part of the namespace being exactly the same ("EZTwain"). Please try renaming the class name to something different, for example "EZTwainClass", does this work this way?
About mixing x# and c#, yes this is of course possible, in separate dlls of the same solution. What is not possible is to include both x# and c# in the same library/dll/exe, that's what Wolfgang was referring to. It's just the term "project" as used by VS that brings this confusion.
as Chris wrote of course you can mix C# and X# in the same solution, but they need to be different executables, as for every executable (exe or dll) only one compiler can be responsible.
So your C# code should build a dll, that then can be used by your X# application (can be exe or dll) without any problem. In the past, I had several examples for this, but now that X# can rebuild all C# features I needed, I have transformed the C# code to X# code.
With .NET you can mix and match languages, but in different assemblies.
So you can have a class in a C# assembly, then inherit from this class in a X# assembly, and then again use (or inherit from) in a VB.NET application.
There are only two limitations: every assembly must be build by one compiler (X#,C#,VB.NET, ....) because in .NET there is no linker anymore like in older application architectures, and if you would like to use an X# class in an assembly written in another language, the class interface cannot use any X# specific extensions, like Date, codeblock or VO style array.