.NET Instantiation Error

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
niladri.sen
Forum Newbie
Posts: 3
Joined: Wed Aug 06, 2014 8:41 am

.NET Instantiation Error

Post by niladri.sen »

First of all I beg your holy pardon for not understanding where to put this post down, of which I have chosen Miscellaneous section.

I was working with PHP version 5.4.19 and was willing to parse few codes through a .dll file which I would create using Visual C# 2010 Express edition.

So, I started and created a Project using Visual C# 2010 as Class Library. This initially loaded my project and dropped me to Class1.cs file. First I changed the file name to MyClass.cs which contains the following line:

[text]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NiladriSen
{
namespace InfoValley
{
namespace Sample
{
public class MyClass
{
protected String myScope;
public void setScope(String scope)
{
this.myScope = scope;
}
public String getScope()
{
return this.myScope;
}
}
}
}
}[/text]

The AssemblyInfo.cs file contains the following line implemented:

[text]...
[assembly: AssemblyCulture("en")]
...
[assembly: ComVisible(true)]
...
[assembly: AssemblyVersion("2.3.X.XXXX")]
[assembly: AssemblyFileVersion("2.3.X.XXXX")]
[assembly: NeutralResourcesLanguageAttribute("en-IN")][/text]

From the Project Properties section, I changed the Target Framework from 4.0 to 3.5 Client Profile, and in the signing section I named it as NiladriSen.InfoValley.Sample and then using the gacutil tool I registered it in GAC with the following command:
gacutil /i NiladriSen.dll
Note: As my namespace for class MyClass reflects as [text]namespace NiladriSen.InfoValley.Sample;[/text] should I need to change the Assembly name as [text]NiladriSen.InfoValley.Sample[/text]?

Finally, when I called this using DOTNET class in PHP as $sample = new DOTNET("NiladriSen, Version=2.3.X.XXXX, Culture=en, PublicKeyToken=XXXXXXXXXXXXXXXX", "NiladriSen.InfoValley.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

If I change the PHP code as $sample = new DOTNET("NiladriSen.InfoValley.Sample, Version=2.3.X.XXXX, Culture=en, PublicKeyToken=XXXXXXXXXXXXXXXX", "NiladriSen.InfoValley.Sample.MyClass"); it threw the following error:

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

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?

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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: .NET Instantiation Error

Post by Weirdan »

You specified proper version and public key token instead of those XXXXs, did you?
niladri.sen
Forum Newbie
Posts: 3
Joined: Wed Aug 06, 2014 8:41 am

Re: .NET Instantiation Error

Post by niladri.sen »

Yes absolutely I did in no time. This in my scenario was:

Code: Select all

$sample = new DOTNET("NiladriSen, Version=2.3.4.2035, Culture=en, PublicKeyToken=e6a7328c4d7e537b", "NiladriSen.InfoValley.Sample.MyClass");
or

Code: Select all

$sample = new DOTNET("NiladriSen.InfoValley.Sample, Version=2.3.4.2035, Culture=en, PublicKeyToken=e6a7328c4d7e537b", "NiladriSen.InfoValley.Sample.MyClass");
Furthermore, where can I obtain the list of "com_exception" with all the hexadecimal values as: "[CreateInstance] [0x80070002]"?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: .NET Instantiation Error

Post by Weirdan »

The hex value you see is marshalled from .NET. 8 is an error indicator (any other value in the first position would mean it's not an error, but a status code), 007 points to Windows32 subsystem, and the rest is an error code itself. Microsoft lists error codes (note: in decimal notation) here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx

This particular error is:
ERROR_FILE_NOT_FOUND
2 (0x2)
The system cannot find the file specified.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: .NET Instantiation Error

Post by Weirdan »

Also see http://blogs.msdn.com/b/yizhang/archive ... 3xxxx.aspx , it deals with .net HRESULTs specifically.
niladri.sen
Forum Newbie
Posts: 3
Joined: Wed Aug 06, 2014 8:41 am

Re: .NET Instantiation Error

Post by niladri.sen »

Thank you Weirdan for such valuable resource you've specified for HRESULT codes. But the glitch I was facing that it generally solved not all purposes which I was intended to gather for C# as in for the code "0x80131522". It might be the whole list of Windows error codes, I didn't know. What exactly I was looking for the HRESULT codes that C# compiler generated during my implementation with PHP. Anyways, thank you once again for your reply.
Post Reply