- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是书中的代码CLR via C# 3e (Microsoft)但它在运行时出错
TypeLoadException was unhandled Could not load type 'MarshalByRefType' from assembly 'CLRviaCSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
除“Main”方法外,所有代码均来自上述书籍。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Runtime.Remoting;
namespace CLRviaCSharp
{
class Program
{
static void Main(string[] args)
{
Marshalling();
}
private static void Marshalling()
{
// Get a reference to the AppDomain that that calling thread is executing in
AppDomain adCallingThreadDomain = Thread.GetDomain();
// Every AppDomain is assigned a friendly string name (helpful for debugging)
// Get this AppDomain’s friendly string name and display it
String callingDomainName = adCallingThreadDomain.FriendlyName;
Console.WriteLine("Default AppDomain’s friendly name={0}", callingDomainName);
// Get & display the assembly in our AppDomain that contains the ‘Main’ method
String exeAssembly = Assembly.GetEntryAssembly().FullName;
Console.WriteLine("Main assembly={0}", exeAssembly);
// Define a local variable that can refer to an AppDomain
AppDomain ad2 = null;
// *** DEMO 1: Cross-AppDomain Communication using Marshal-by-Reference ***
Console.WriteLine("{0}Demo #1", Environment.NewLine);
// Create new AppDomain (security & configuration match current AppDomain)
ad2 = AppDomain.CreateDomain("AD #2", null, null);
MarshalByRefType mbrt = null;
// Load our assembly into the new AppDomain, construct an object, marshal
// it back to our AD (we really get a reference to a proxy)
mbrt = (MarshalByRefType)
ad2.CreateInstanceAndUnwrap(exeAssembly, "MarshalByRefType");
Console.WriteLine("Type={0}", mbrt.GetType()); // The CLR lies about the type
// Prove that we got a reference to a proxy object
Console.WriteLine("Is proxy={0}", RemotingServices.IsTransparentProxy(mbrt));
// This looks like we’re calling a method on MarshalByRefType but, we’re not.
// We’re calling a method on the proxy type. The proxy transitions the thread
// to the AppDomain owning the object and calls this method on the real object.
mbrt.SomeMethod();
// Unload the new AppDomain
AppDomain.Unload(ad2);
// mbrt refers to a valid proxy object; the proxy object refers to an invalid AppDomain
try
{
// We’re calling a method on the proxy type. The AD is invalid, exception is thrown
mbrt.SomeMethod();
Console.WriteLine("Successful call.");
}
catch (AppDomainUnloadedException)
{
Console.WriteLine("Failed call.");
}
// *** DEMO 2: Cross-AppDomain Communication using Marshal-by-Value ***
Console.WriteLine("{0}Demo #2", Environment.NewLine);
// Create new AppDomain (security & configuration match current AppDomain)
ad2 = AppDomain.CreateDomain("AD #2", null, null);
// Load our assembly into the new AppDomain, construct an object, marshal
// it back to our AD (we really get a reference to a proxy)
mbrt = (MarshalByRefType)
ad2.CreateInstanceAndUnwrap(exeAssembly, "MarshalByRefType");
// The object’s method returns a COPY of the returned object;
// the object is marshaled by value (not be reference).
MarshalByValType mbvt = mbrt.MethodWithReturn();
// Prove that we did NOT get a reference to a proxy object
Console.WriteLine("Is proxy={0}", RemotingServices.IsTransparentProxy(mbvt));
// This looks like we’re calling a method on MarshalByValType and we are.
Console.WriteLine("Returned object created " + mbvt.ToString());
// Unload the new AppDomain
AppDomain.Unload(ad2);
// mbvt refers to valid object; unloading the AppDomain has no impact.
try
{
// We’re calling a method on an object; no exception is thrown
Console.WriteLine("Returned object created " + mbvt.ToString());
Console.WriteLine("Successful call.");
}
catch (AppDomainUnloadedException)
{
Console.WriteLine("Failed call.");
}
// DEMO 3: Cross-AppDomain Communication using non-marshalable type ***
Console.WriteLine("{0}Demo #3", Environment.NewLine);
// Create new AppDomain (security & configuration match current AppDomain)
ad2 = AppDomain.CreateDomain("AD #2", null, null);
// Load our assembly into the new AppDomain, construct an object, marshal
// it back to our AD (we really get a reference to a proxy)
mbrt = (MarshalByRefType)
ad2.CreateInstanceAndUnwrap(exeAssembly, "MarshalByRefType");
// The object’s method returns an non-marshalable object; exception
NonMarshalableType nmt = mbrt.MethodArgAndReturn(callingDomainName);
// We won’t get here...
}
}
// Instances can be marshaled-by-reference across AppDomain boundaries
public sealed class MarshalByRefType : MarshalByRefObject
{
public MarshalByRefType()
{
Console.WriteLine("{0} ctor running in {1}",
this.GetType().ToString(), Thread.GetDomain().FriendlyName);
}
public void SomeMethod()
{
Console.WriteLine("Executing in " + Thread.GetDomain().FriendlyName);
}
public MarshalByValType MethodWithReturn()
{
Console.WriteLine("Executing in " + Thread.GetDomain().FriendlyName);
MarshalByValType t = new MarshalByValType();
return t;
}
public NonMarshalableType MethodArgAndReturn(String callingDomainName)
{
// NOTE: callingDomainName is [Serializable]
Console.WriteLine("Calling from ‘{0}’ to ‘{1}’.",
callingDomainName, Thread.GetDomain().FriendlyName);
NonMarshalableType t = new NonMarshalableType();
return t;
}
}
// Instances can be marshaled-by-value across AppDomain boundaries
[Serializable]
public sealed class MarshalByValType : Object
{
private DateTime m_creationTime = DateTime.Now; // NOTE: DateTime is [Serializable]
public MarshalByValType()
{
Console.WriteLine("{0} ctor running in {1}, Created on {2:D}",
this.GetType().ToString(),
Thread.GetDomain().FriendlyName,
m_creationTime);
}
public override String ToString()
{
return m_creationTime.ToLongDateString();
}
}
// Instances cannot be marshaled across AppDomain boundaries
// [Serializable]
public sealed class NonMarshalableType : Object
{
public NonMarshalableType()
{
Console.WriteLine("Executing in " + Thread.GetDomain().FriendlyName);
}
}
}
最佳答案
当您使用AppDomain.CreateInstanceAndUnwrap方法时,您应该将类型的全名传递给typeName参数。所以,替换
ad2.CreateInstanceAndUnwrap(exeAssembly, "MarshalByRefType");
与
ad2.CreateInstanceAndUnwrap(exeAssembly, typeof(MarshalByRefType).FullName);
关于c#-4.0 - 无法从程序集 'MarshalByRefType' 加载类型 'CLRviaCSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066161/
我想将一个应用程序分发到许多不同的国家,所以我必须将多语言字符串嵌入到它的资源中。 Visual Studio 提供了日文、英文、中文等世界主流语言的列表,但除此之外,还有其他三种选择: "Neutr
我有一个安装了 Wordpress 的 Ubuntu 服务器。从服务器发送电子邮件时,我收到以下 header : Received-Spf: neutral. 我确实在以下事项中设置了 SPF 记录
如何更改用 C# 编写的 DLL 的语言属性? 我尝试进入 Project Properties -> Assembly Information -> Neutral Language ComboBo
当我尝试使用 php 向我的 gmail 地址发送电子邮件时,我收到了电子邮件,但 spf 存在问题。它说 Received-SPF:中性 但这里的 spf 记录似乎不错 http://mxtoolb
在大多数情况下,我发现polarity_scores返回的输出为“Neutral”,而负面和正面情绪应有一定的百分比突出显示,例如考虑以下情况,我发现了下面提到的所有3种情况的{'neg': 0.0,
正如MSDN所述: If you are writing a single threaded application (or a multi-threaded application where on
我正在试验 CoNat 的定义取自 this paper作者:Jesper Cockx 和 Andreas Abel: open import Data.Bool open import Relati
我正在 Visual Studio 2017 中的 Allegro 5 游戏中实现操纵杆控件。我尝试过两种方式:让我的事件队列在我的主循环中监听操纵杆事件,并使用 ALLEGRO_JOYSTICK_S
鉴于我的 html 结构为: My header My page-specific content My footer 我希望 JQM.js(和 J
我正在阅读 Herbert Schildt 的书“Java:完整引用”,他在其中写道 Java 是可移植的并且与体系结构无关。这两个概念有什么区别?我无法从文本中理解它。 最佳答案 看看这个white
我这里的东西完全符合我的要求。我的问题是它似乎过于复杂,是否有更快/更好的方法来进行我在下面显示的 pitchAngleRadians 计算? 显示代码...(连同两张图片) 第一张图片是 atan2
MAKELANGID 的文档指定 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) 表示“语言中性”。 这在我的机器上似乎是英文的(用FormatMessage 试过
我想允许 Google Apps 和 CampaignMonitor(电子邮件营销服务)从我的域发送电子邮件。 我已将我的 TXT 记录设置为: v=spf1 a mx include:_spf.go
我有以下代码片段 DateTime date1; CultureInfo neutralCulture = new CultureInfo("fr"); bool isNeutral = neutra
有时我想在其他几个 HTML 元素周围放置一个包装器元素,唯一的目的是设置一个方便的 CSS 选择器来引用所有包含的元素: ... ...
当我有大量复杂的代码块时,我通常会使用比要求更多的括号集。我的代码可能如下所示: library(tidyverse) mtcars %>% mutate(name = rownames(.))
我认为 exception strong 意味着程序要么成功结束,要么如果没有成功结束,它会保持数据不变,但我不确定什么是 exception neutral方法。有人可以定义这两个术语吗? 最佳答案
我遇到了一个使用内置全局化工具的 ASP.NET 应用程序崩溃的情况。 在带有 Culture="auto"指令的 ASP.NET 页面上,使用中性文化作为其浏览器语言(例如“zh-Hans”)的用户
我知道之前有人问过这个问题,但给出的答案是临时破解的。 我们的网站已经在我们的实时服务器上运行了一段时间,我们刚刚进行了一些更新和部署。最初 JIT 运行并且站点工作。下一次刷新应用程序池时,我们从网
我有三个 Dotnet Core 2.0 项目; Angular、Domain 和 EF7。Domain 和 EF7 是 .NETStandard 库,Angular 是 Core 2.0 Angul
我是一名优秀的程序员,十分优秀!