我一直在尝试使用以下代码(所有内容都在同一个程序集中定义):
namespace SomeApp{
public class A : MarshalByRefObject
{
public byte[] GetSomeData() { // }
}
public class B : MarshalByRefObject
{
private A remoteObj;
public void SetA(A remoteObj)
{
this.remoteObj = remoteObj;
}
}
public class C
{
A someA = new A();
public void Init()
{
AppDomain domain = AppDomain.CreateDomain("ChildDomain");
string currentAssemblyPath = Assembly.GetExecutingAssembly().Location;
B remoteB = domain.domain.CreateInstanceFromAndUnwrap(currentAssemblyPath,"SomeApp.B") as B;
remoteB.SetA(someA); // this throws an ArgumentException "Object type cannot be converted to target type."
}
}
}
Run Code Online (Sandbox Code Playgroud)
我要做的是将第一个AppDomain中创建的"A"实例的引用传递给子域,并让子域在第一个域上执行方法.在'B'代码的某些方面,我将调用'remoteObj.GetSomeData()'.必须这样做,因为'GetSomeData'方法中的'byte …
如何将嵌入资源作为ITemplate加载?LoadTemplate()方法只接受字符串虚拟路径,显然这对嵌入式资源不起作用.
我使用.NET 4.0创建并编译了我的Windows服务所以我转到.NET 4.0文件夹并说出类似这样的内容:我将bin文件夹复制到C驱动器以缩短路径:
InstallUtil.exe"C:\ bin\Debug\MyTestService.exe"
这是我得到的错误:
初始化安装时发生异常:System.BadImageFormatException:无法加载文件或程序集'file:/// C:\ bin Debug\MyTestService.exe'或其依赖项之一.尝试加载格式不正确的程序.
所以我不知道该怎么办.
我正在使用msdn示例代码,它有jsonp包装文件,你可以在这里找到代码
这个的文章和MSDN文章JSON填充(AJAX)
但是当我运行代码时它会抛出这个错误:
Encountered invalid root element name 'HTML'. 'root' is the only allowed root element name
这是什么意思?