Object reference error while including non pure mode dll

Discussion about the open-source Phalanger [?] project.

Object reference error while including non pure mode dll

Postby rushi216 » April 19th, 2016, 4:52 am

I want to consume simple php library in c# application, for that I have simple php class like below,

Code: Select all
class SampleObj
{
    public $Message = "Hello world!";

    function Write($arg)
    {
        echo $arg."\n";
    }

    function Add($a, $b)
    {
        return $a + $b;
    }
}

I am converting this into dll using below command

Code: Select all
phpc /target:dll /out:objects.dll objects.php


Now i am using it in c# console application by below code

Code: Select all
ScriptContext ctx = ScriptContext.CurrentContext;
ctx.Output = Console.Out;
ctx.Include("objects.php", false);

I have also added below in App.config file and gave reference to objects.dll in project references

Code: Select all
<phpNet>
    <classLibrary>
      <add assembly="mscorlib"/>
      <!--<add assembly="objects, Version=1.0.0.0" />-->
      <add url="objects.dll" />
    </classLibrary>
</phpNet>

Still I am having exception like below

{"Library assembly 'file:///C:/CSharpConsole/bin/Debug/objects.dll' could not be loaded. Object reference not set to an instance of an object."}

at PHP.Core.AssemblyLoader.Load(String assemblyName, Uri assemblyUrl, LibraryConfigStore config)
at PHP.Core.PhpConfigurationContext.LoadLibrary(String assemblyName, Uri assemblyUrl, String sectionName, XmlNode node)
at PHP.Core.LibrariesConfigurationList.LoadLibrariesNoLock(Func5 callback, Action1 parseSectionCallback)
at PHP.Core.ConfigurationSectionHandler.GetConfig(ApplicationContext appContext, String sectionName)
at PHP.Core.Configuration.Load(ApplicationContext appContext)
at PHP.Core.ScriptContext..ctor(ApplicationContext appContext)
at PHP.Core.ScriptContext.CreateDefaultScriptContext()
at PHP.Core.ScriptContext.get_CurrentContext()
at CSharpConsole.Program.Main(String[] args) in C:\Users\rushi.PROMACT\Downloads\ducktyping\CSharpConsole\Program.cs:line 28
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

What could be the issue?
rushi216
 
Posts: 2
Joined: April 19th, 2016, 4:49 am

Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 16 guests

cron

User Control Panel

Login

Who is online

In total there are 16 users online :: 0 registered, 0 hidden and 16 guests (based on users active over the past 5 minutes)
Most users ever online was 256 on March 28th, 2024, 9:42 am

Users browsing this forum: No registered users and 16 guests