异常“System.InvalidProgramException:JIT 编译器遇到内部限制”已经发生
示例代码:
下面的代码不完整,但足以显示我面临的wt问题。
namespace ClassLibrary1
{
class Class1
{
internal static void sum(ref List<TestClass> a, int b)
{
//some code
}
}
}
同一程序集中还有另一个类
namespace ClassLibrary1
{
class TestClass
{
//code
}
}
当我为方法 sum 创建单元测试用例时,
[TestMethod()]
public void sumTest()
{
List<TestClass_Accessor> lstTestClass = new List<TestClass_Accessor>();
Class1_Accessor.sum(ref lstTestClass, b);
}
,那么代码将类似于问题:在上面的代码中,我正在创建 TestClass 类型的列表,但它是私有类,因此 VSTS 创建 TestClass_Accessor 来访问类功能。 在方法 Sum 中,它将参数作为“TestClass”类型列表的引用。
我还调试了我的代码,但是当调试
Class1_Accessor.sum(ref lstTestClass, b);
时,它会抛出异常“System.InvalidProgramException:JIT 编译器遇到内部限制”。
当我创建字符串类型列表时,它就可以工作,即列表没有问题。
根据我的理解,问题在于列表的类型。在单元测试中,我们创建 TestClass_Accessor
类型的列表。
在类列表中,类型为 List
。
请为此提供解决方案。
问候,
尼廷·萨胡
Sample code:
Below code is not complete but it is enough to show wt problem i am facing.
namespace ClassLibrary1
{
class Class1
{
internal static void sum(ref List<TestClass> a, int b)
{
//some code
}
}
}
There is another class in same assembly
namespace ClassLibrary1
{
class TestClass
{
//code
}
}
when I create unit test case for method sum then code would be like
[TestMethod()]
public void sumTest()
{
List<TestClass_Accessor> lstTestClass = new List<TestClass_Accessor>();
Class1_Accessor.sum(ref lstTestClass, b);
}
Problem: In above code I am creating list of type TestClass but it is private class so VSTS create TestClass_Accessor to access class functionality.
In method Sum, It takes parameter as a reference of list of type "TestClass".
I have also debug my code but when
Class1_Accessor.sum(ref lstTestClass, b);
is debugged it throws exception "System.InvalidProgramException: JIT Compiler encountered an internal limitation ".
When i created list of string type then it works i.e. list has no problem.
As per my understanding problem is in type of list. in unit test we create list of type TestClass_Accessor
.
And in class list has type List<TestClass>
.
please provide solution for this.
Regards,
Nitin Sahu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法理解您所说的内容。但...
TestClass 在您提供的代码中不是私有的。默认情况下,当未指定访问修饰符时,它是内部的。您可以在测试中轻松访问内部成员。当你消除额外的东西(TestClass_Accessor)时,也许你不会有任何问题。
看这里:如何测试框架是否单元测试位于单独的程序集中?
顺便说一句,传递引用值时不需要
ref
。I have problems understanding what You are saying. But...
TestClass is not private in code You provided. By default it is internal when no access modifier is specified. And You can easily access internal members in Your tests. Maybe You won't have any problems when You eliminate additional stuff (TestClass_Accessor).
Look here: How to test Framework if Unit tests are in separate assembly?
And BTW You don't need
ref
when passing reference values.使用“ref”是这里问题的一部分。我遇到了同样的问题,当不使用“ref”关键字时它就消失了。
正如 Peri 已经说过的,这里不需要使用 ref 。
Using "ref" is part of the problem here. I had the same problem and it went away when not using the "ref" keyword.
As Peri already stated, using ref is not needed here.