.NET Instantiation Error

4

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:

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:

...
[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

$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

Stack trace:
#0 C:\Users\*******\Desktop\Sample.php(2): dotnet->dotnet('Sample, Ver...','Sample.MyClass')
#1 {main}
  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:

$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

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?

c#
php
.net
visual-studio-2010
asked on Stack Overflow Aug 7, 2014 by Niladri Sen

1 Answer

0

Can you try compiling your dlll to x86 instead of MSIL?

I would go for enabling the fusion log and seeing what is going on there, that way you will able to see from where is trying to load your assembly.

How to enable assembly bind failure logging (Fusion) in .NET

answered on Stack Overflow Mar 4, 2015 by Juan • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0