Click here to Skip to main content
15,891,880 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
First of all, sorry for this extra descriptive question.

I was implementing my own assembly rather calling anything from GAC! I started with a Class Library project in Visual C# 2010 Express edition. The file Class1.cs looked very simple as:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sample
{
    public class MyClass
    {
        public String generateCode(String s, Array a)
        {
            return "function " + s " + "(" + a + ") { return a['#handler']; }";
        }
    }
}


Note: Changing either the name of the file to MyClass.cs or even the classname to Class1 does even throw the same exception described hereunder.

The AssemblyInfo.cs file contains the following line implemented:

C#
...
[assembly: AssemblyCulture("en")]
...
[assembly: ComVisible(true)]
...
[assembly: AssemblyVersion("2.3.5.2034")]
[assembly: AssemblyFileVersion("2.3.5.2034")]
[assembly: NeutralResourcesLanguageAttribute("en-IN")]


Then using the gacutil tool I registered it in GAC with the following command:

gacutil /f /i Sample.dll


Note: In my scenario, the arguments -f and -i had no effect in registering this file into GAC.

And therefore I came up with the same .dll file that resides in {ProjectFolder}\bin\Release\ path at
%WINDIR%\Microsoft.NET\assembly\GAC_MSIL\Sample\v4.0_2.3.5.2034_en_d328b945b0050bbe\
path.

Finally, when I called this using DOTNET class in PHP as

C#
$sample = new DOTNET("Sample, Version=2.3.5.2034, Culture=en, PublicKeyToken=d328b945b0050bbe", "Sample.MyClass");


it threw the following error:

PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80070002] The system cannot find the file specified.' in C:\Users\*******\Desktop\Sample.php:2<br />
<br />
Stack trace:<br />
#0 C:\Users\*******\Desktop\Sample.php(2): dotnet->dotnet('Sample, Ver...','Sample.MyClass')<br />
#1 {main}<br />
  thrown in C:\Users\*******\Desktop\Sample.php on line 2


Again If I use the following code, after moving the main class into different namespace as
namespace Sample.DotNet.myCompany;
it threw a different error:

C#
$sample = new DOTNET("Sample, Version=2.3.5.2034, Culture=en, PublicKeyToken=d328b945b0050bbe", "Sample.DotNet.myCompany.MyClass");


This threw:

PHP Fatal error: Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80131522] ' in C:\Users\*******\Desktop\Sample.php:2

Note:

I am using Vista Home Basic (SP 2), Visual C# 2010 Express edition, PHP 5.4.19, Apache 2.2 & 2.4 versions
I signed this file with no password set at all in Project Properties section.
I even have included a line com.dotnet_runtime = "v4.0.30319" to my php.ini
This luckily is not seem to be a PHP problem as expected, because I changed the assembly Target Framework from 4.0 to 3.5 Client Profile in the Project Properties section. It then apparently been visible in %windir%\assembly\ directory, but failed to produce any satisfactory solution.

Moreover, If I even change the namespace from namespace Sample to

C#
namespace Sample.DotNet.myCompany;

in the main file for which the class reflects as Sample.DotNet.myCompany.MyClass, and apply the same thing, it rather failed to do what I needed.

Conclusion: Nothing made any right solution in my case!

Question: Is there any way to fix this up? Elaborately, can I use that particular .dll file created using Visual C# 2010 in PHP 5.4.19 at all?
Posted
Updated 28-Aug-14 3:37am
v2
Comments
Sergey Alexandrovich Kryukov 28-Aug-14 15:50pm    
"... implementing own assembly..." Sound very weird, as if there were any alternatives for .NET programming without creating "own assemblies". After these words, it's hard to continue reading, because it's so hard to believe that the rest of the post may make any sense. :-)
—SA
Sergey Alexandrovich Kryukov 28-Aug-14 15:59pm    
1) Try to use simple name (only make sure you have only one version in the GAC):
$sample = new DOTNET("Sample", "....MyClass");
2) Make sure your Mono version used by Apache mod_mono is compatible with the target .NET version of your assembly.
3) If you have Apache with mod_mono already, why not using ASP.NET for Apache instead?
—SA
j snooze 29-Aug-14 17:47pm    
In the project properties page under the "Build" tab, do you have the Register for COM interop checked? I've never done the php thing, but it sounds like it has to use COM to communicate.
NILADRI SEN 30-Aug-14 9:33am    
Thanks to SA and Snooze for your answers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900