Dans mon application ASP.NET, il existe la classe MyAssembly.CustomIdentity
et l'environnement d'exécution .NET tries to serialize that class. Au cours de la sérialisation, il lance FileNotFoundException
se plaindre qu'il ne peut pas charger MyAssembly
.AssemblyResolve n'est pas appelé et FileNotFoundException est levé pendant la sérialisation
[SerializationException: Unable to find assembly 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9464367
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
System.AppDomain.get_Id() +0
<CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +151
<CrtImplementationDetails>.DefaultDomain.Initialize() +30
<CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport*) +41
<CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport*) +391
<CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*) +65
[ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.]
<CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException) +61
<CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*) +113
.cctor() +46
[TypeInitializationException: The type initializer for '<Module>' threw an exception.]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() +0
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() +809
[TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable() +17
SampleWebApp.Default.Page_Load(Object sender, EventArgs e) in C:\Temp\AzureAdvancedRolesSource\Ex2-StartupTasks\CS\Begin\SampleWebApp\Default.aspx.cs:22
J'ai cherché et ressemble à la gestion des événements AppDomain.AssemblyResolve
devrait aider. Donc, je mis en œuvre la manipulation de cet événement:
public partial class Default : System.Web.UI.Page
{
static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
return typeof(MyAssembly.CustomIdentity).Assembly;
}
protected void Page_Load(object sender, EventArgs e)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve +=
new ResolveEventHandler(MyResolveEventHandler);
// this code throws `FileNotFoundException`
// during a serialization attempt
bool isAvailable =
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable;
}
}
mais mon gestionnaire est pas invoqué et j'ai toujours la même exception lors d'une tentative de sérialisation. Comment puis-je résoudre ce problème - comment faire pour que le sérialiseur trouve mon assembly?
Quel est le message d'exception? – SLaks
Pour commencer, vous ne devriez pas ** aveuglément ** retourner votre assemblée; vous devez vérifier 'args' pour voir ce qu'il demande ... mais: quel est le message d'exception maintenant? –
@SLaks, @Marc Gravell :: J'ai ajouté la pile d'appels et je suppose qu'elle a fourni le message avec le plus de détails. – sharptooth