PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue May 23, 2017 3:38 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: .NET Instantiation Error
PostPosted: Wed Aug 06, 2014 9:09 am 
Offline
Forum Newbie

Joined: Wed Aug 06, 2014 8:41 am
Posts: 3
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:

Syntax: [ Download ] [ Hide ]
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;
                }
            }
        }
    }
}


The AssemblyInfo.cs file contains the following line implemented:

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


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:

Quote:
gacutil /i NiladriSen.dll


Note: As my namespace for class MyClass reflects as
Syntax: [ Download ] [ Hide ]
namespace NiladriSen.InfoValley.Sample;
should I need to change the Assembly name as
Syntax: [ Download ] [ Hide ]
NiladriSen.InfoValley.Sample
?

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.


Top
 Profile  
 
PostPosted: Thu Aug 07, 2014 6:31 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5975
Location: Odessa, Ukraine
You specified proper version and public key token instead of those XXXXs, did you?


Top
 Profile  
 
PostPosted: Thu Aug 07, 2014 7:52 am 
Offline
Forum Newbie

Joined: Wed Aug 06, 2014 8:41 am
Posts: 3
Yes absolutely I did in no time. This in my scenario was:

Syntax: [ Download ] [ Hide ]
$sample = new DOTNET("NiladriSen, Version=2.3.4.2035, Culture=en, PublicKeyToken=e6a7328c4d7e537b", "NiladriSen.InfoValley.Sample.MyClass");


or

Syntax: [ Download ] [ Hide ]
$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]"?


Top
 Profile  
 
PostPosted: Fri Aug 08, 2014 10:44 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5975
Location: Odessa, Ukraine
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:
Quote:
ERROR_FILE_NOT_FOUND
2 (0x2)
The system cannot find the file specified.


Top
 Profile  
 
PostPosted: Fri Aug 08, 2014 10:50 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5975
Location: Odessa, Ukraine
Also see http://blogs.msdn.com/b/yizhang/archive ... 3xxxx.aspx , it deals with .net HRESULTs specifically.


Top
 Profile  
 
PostPosted: Sat Aug 09, 2014 8:47 am 
Offline
Forum Newbie

Joined: Wed Aug 06, 2014 8:41 am
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group