.NET实例化错误 [英] .NET Instantiation Error

查看:49
本文介绍了.NET实例化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,抱歉这个额外的描述性问题。



我正在实施自己的程序集而不是从GAC调用任何东西!我开始使用Visual C#2010 Express版中的类库项目。文件Class1.cs看起来很简单:



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']; }";
        }
    }
}





注意:将文件名更改为 MyClass.cs 甚至是 Class1 的类名甚至会抛出下面描述的相同异常。



AssemblyInfo.cs 文件包含以下实现的行:





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")]





然后使用gacutil工具我在GAC中注册了它以下命令:





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

gacutil /f /i Sample.dll





注意:在我的场景中,参数 -f -i 将此文件注册到GAC没有任何效果。



因此我想出了位于 {ProjectFolder} \bin\Release\ path at



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\

路径。



最后,当我使用PHP中的DOTNET类调用它时



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<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:

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





抛出:



PHP致命错误:未捕获异常'com_exception'消息'无法在C:\Users\ ******* \Desktop \Sample.php中实例化.Net对象[CreateInstance] [0x80131522]:2



注意



我使用的是Vista Home Basic(SP 2), Visual C#2010 Express版,PHP 5.4.19,Apache 2.2& 2.4版本

我签署了这个文件,项目属性部分没有设置任何密码。

我甚至包括一行com.dotnet_runtime =v4.0.30319到我的php.ini

幸运的是,这似乎不是预期的PHP问题,因为我在Project Properties部分中将程序集Target Framework从4.0更改为3.5 Client Profile。然后它显然在%windir%\assembly \ 目录中可见,但未能产生任何令人满意的解决方案。



此外,如果我甚至将名称空间从名称空间Sample更改为





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;



在主文件中,该类反映为 Sample.DotNet.myCompany.MyClass ,并应用相同的东西,它没有做我需要的。



结论:没有任何权利在我的情况下的解决方案!



问题:有什么方法可以解决这个问题吗?精心设计,我可以使用PHP 5.4.19中使用Visual C#2010创建的特定.dll文件吗?


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?

推荐答案

sample = new DOTNET( Sample,Version = 2.3.5.2034,Culture = en,PublicKeyToken = d328b945b0050bbe Sample.MyClass);
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:


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





抛出:



PHP致命错误:未捕获的异常'com_exception',消息'无法实例化.Net对象[CreateInstance] [0x80131522] '在C:\ Users \ ******* \Desktop \Sample.php:2



< b>注意:



我正在使用Vista Home Ba sic(SP 2),Visual C#2010 Express Edition,PHP 5.4.19,Apache 2.2& 2.4版本

我签署了这个文件,项目属性部分没有设置任何密码。

我甚至包括一行com.dotnet_runtime =v4.0.30319到我的php.ini

幸运的是,这似乎不是预期的PHP问题,因为我在Project Properties部分中将程序集Target Framework从4.0更改为3.5 Client Profile。然后它显然在%windir%\assembly \ 目录中可见,但未能产生任何令人满意的解决方案。



此外,如果我甚至将名称空间从名称空间Sample更改为





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;



在主文件中,该类反映为 Sample.DotNet.myCompany.MyClass ,并应用相同的东西,它没有做我需要的。



结论:没有任何权利在我的情况下的解决方案!



问题:有什么方法可以解决这个问题吗?我可以精心地使用PHP 5.4.19中使用Visual C#2010创建的特定.dll文件吗?


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?


这篇关于.NET实例化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆