Object reference error while including non pure mode dll
1 post
• Page 1 of 1
Object reference error while including non pure mode dll
I want to consume simple php library in c# application, for that I have simple php class like below,
I am converting this into dll using below command
Now i am using it in c# console application by below code
I have also added below in App.config file and gave reference to objects.dll in project references
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?
- 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
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests