Calling a class that has no public constructor

This forum is meant for questions and discussions about the X# language and tools
Anonymous

Calling a class that has no public constructor

Post by Anonymous »

How can I solve this ? The Vegas class has no public constructor

#using ScriptPortal.Vegas

FUNCTION Start( ) AS VOID
LOCAL oVegas AS Vegas

oVegas:=Vegas{}

error XS1729: 'Vegas' does not contain a constructor that takes 0 arguments

Vegas is a class part of the video-edting software Sony Vegas,
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Calling a class that has no public constructor

Post by Phil Hepburn »

The message says it does not have a constructor which takes zero arguments - BUT - the does not mean that it has no constructor.

Try supplying one or more nulls !?

Just a thought off the top of my head.

Cheers,
Phil.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Calling a class that has no public constructor

Post by robert »

JP,

What Phil said, or there is a static method in the class or a static property that allows you to create/access instances.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
jpmaertens

Calling a class that has no public constructor

Post by jpmaertens »

When I right click on the Vegas{} to see the parameters, it says it has no public constructor.

Of course I tried with 1...4 null parameters, the resulting error is : it has no constructor with 1..4 parameters.
jpmaertens

Calling a class that has no public constructor

Post by jpmaertens »

I tried to do this simple test

cTest:=Vegas:Version

the Xide interface shows all methods and accesses of Vegas when I type the :

This however gives another compiler error :

error XS0120: An object reference is required for the non-static field, method, or property 'Vegas.Version'
George
Posts: 106
Joined: Thu Nov 05, 2015 9:17 am

Calling a class that has no public constructor

Post by George »

Jean-Pierre,

you have to type:
cTest := Vegas.Version to access a Static-Class member
jpmaertens

Calling a class that has no public constructor

Post by jpmaertens »

Thank you, but does not work either.
User avatar
Fabrice
Posts: 458
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Calling a class that has no public constructor

Post by Fabrice »

Hi Jean-Pierre,
that's the kind of scenario where you don't need to call the constructor, either :
. because you must use a static Method that will always return the same Vegas object that is created internally, so you have a Singleton
. because you will receive the Vegas object when your code is called by the application that will consume your extension (Here that's my favorite option)

Hope this helps.

Cheers,
Fabrice
XSharp Development Team
fabrice(at)xsharp.eu
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Calling a class that has no public constructor

Post by Chris »

Hi Jean-Pierre,

It is a bug of XIDE that it shows members on "Vegas:", ":" is used on instances of types only, is not valid on types themselves, so this should show nothing. But try a dot instead, to see the static members of the class, with "Vegas.", does the list now contain an entry like "Create", "CreateInstance" or something like that?

In any case, as others already pointed out, the fact that there does not exist a public constructor means that the developer of the class did not intend (and does not allow) to let the programmer create an instance of this class directly. Instead they must have provided another means of getting such an instance, but it's too hard to say how, without some documentation or without looking at the full contents of the dll in a disassembler like ILSpy or Reflector. Is there some documentation for this library? If not, would it be possible to zip and upload it for us to have a look?

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
jpmaertens

Calling a class that has no public constructor

Post by jpmaertens »

Hello Fabrice,

I was just trying to translate a c# sample.
this is the sample :

using System;
using System.Text;
using System.Windows.Forms;
using ScriptPortal.Vegas;

namespace SampleScript1
{
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
MessageBox.Show(vegas.Version);
}
}
}

That is all. I can't generate code to run inside Vegas, when I have compiler errors. It is also very puzzling because when I type Vegas: the IDE shows me all the methods and accesses of Vegas.


#using System
#using System.Windows.Forms
#using ScriptPortal.Vegas


FUNCTION start() AS VOID

MessageBox.Show(Vegas:version) // error XS0120: An object reference is required for the non-static field, method, or property 'Vegas.Version'

RETURN
Post Reply