Xbase++ forum

This forum is meant for questions about the XBase++ Language support in X#.

User avatar
DenGhostYY
Posts: 6
Joined: Fri Sep 16, 2022 8:23 am

Re: Xbase++ forum

Post by DenGhostYY »

Error XS0579 Duplicate 'global::XSharp.Internal.ClassLibraryAttribute' attribute

AssemblyInfo.prg

Code: Select all

USING System.Reflection
USING System.Runtime.CompilerServices
USING System.Runtime.InteropServices
USING XSharp.Internal

//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("SandBoxXSharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SandBoxXSharp")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ClassLibrary("XbTools", "XbTools")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(FALSE)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9c904023-2d57-4483-99c1-ca750397563b")]

//
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("1.0.*")]
What am I doing wrong?
User avatar
robert
Posts: 4189
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Xbase++ forum

Post by robert »

When compiling with X# you do not add the ClassLibrary Attribute yourself. The compiler does that for you and includes the name of the class that it generated that contains all the functions in your assembly.
Only if you code in C# then you have to add this attribute.
If you want to tell the compiler about additional namespaces, then you should use the ImplicitNamespace attribute. There can be more than one of this attribute.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
DenGhostYY
Posts: 6
Joined: Fri Sep 16, 2022 8:23 am

Re: Xbase++ forum

Post by DenGhostYY »

Yes, I want to use a class library written in C# in an X# project. Unfortunately, applying the specified attributes does not allow me to compile the X# console application. Can I see such examples or send you my solution (.sln) that doesn't work?
User avatar
wriedmann
Posts: 3631
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Xbase++ forum

Post by wriedmann »

Hi,
to use a C# library in an X# project you don't need anything - just add it in the references and use it.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
DenGhostYY
Posts: 6
Joined: Fri Sep 16, 2022 8:23 am

Re: Xbase++ forum

Post by DenGhostYY »

How to make it so that there is no need to write

Code: Select all

using static XbTools.XbTools
in prg file?
User avatar
robert
Posts: 4189
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Xbase++ forum

Post by robert »

DenGhostYY wrote: Tue Dec 19, 2023 7:43 pm How to make it so that there is no need to write

Code: Select all

using static XbTools.XbTools
in prg file?
If you write the code as a function then the compiler generates the ClassLibrary attribute.
There is no easy way to automatically add USING STATIC commands to a project.
If you want to centralize code in a class, you can also create a function that calls that method.
We have done that on several locations in the runtime too:
For example:

Code: Select all

FUNCTION MemVarGet(cVarName AS STRING) AS USUAL
    RETURN XSharp.MemVar.Get(cVarName)
We are planning support for GLOBAL USING and GLOBAL USING STATIC in a future release.
When that is available then you can add this in one location and it will work in the whole project.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4189
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Xbase++ forum

Post by robert »

Den,

To make the X# compiler automatically recognize your C# static method as a function, you will have to add an attribute to the C# assembly (and not the X# assembly)
The code below assumes that the functions are in the XbTools.XbTools class, and that the namespace XbTools may contain classes that you want the compiler to automatically recognize.

Code: Select all

using XSharp;
using XSharp.Internal;
[assembly: ClassLibrary("XbTools.XbTools", "XbTools")]
The ClassLibrary attribute can only appear once.

If you have more namespaces that you want the compiler to automatically include when searching for class you can add the ImplicitNamespace attribute as well

Code: Select all

[assembly: ImplicitNamespace("XbTools.Data")]
[assembly: ImplicitNamespace("XbTools.Support")]
The ImplicitNamespace attribute can be added more than once.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply