Fix method wiping (#1448)
* Fix wiping assemblies that contain references to others in same directory * Fix generated IL for reporting calls to wiped methods * Add E2E test for method wiping
This commit is contained in:
parent
d4e2c28145
commit
b2f73492f5
|
|
@ -36,6 +36,14 @@
|
||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>Invoke wiped method</legend>
|
||||||
|
<form id="invokeWipedMethod">
|
||||||
|
<button type="submit" disabled>Go</button>
|
||||||
|
<div><textarea rows="5" cols="80" readonly id="invokeWipedMethodStackTrace"></textarea></div>
|
||||||
|
</form>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Call JS from .NET</legend>
|
<legend>Call JS from .NET</legend>
|
||||||
<form id="callJs">
|
<form id="callJs">
|
||||||
|
|
@ -103,6 +111,16 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
el('invokeWipedMethod').onsubmit = function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
try {
|
||||||
|
invokeMonoMethod('MonoSanityClient', 'MonoSanityClient', 'Examples', 'InvokeWipedMethod', []);
|
||||||
|
el('invokeWipedMethodStackTrace').value = 'WARNING: No exception occurred';
|
||||||
|
} catch (ex) {
|
||||||
|
el('invokeWipedMethodStackTrace').value = ex.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
el('callJs').onsubmit = function (evt) {
|
el('callJs').onsubmit = function (evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var expression = el('callJsEvalExpression').value;
|
var expression = el('callJsEvalExpression').value;
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@
|
||||||
'mscorlib',
|
'mscorlib',
|
||||||
'System',
|
'System',
|
||||||
'System.Core',
|
'System.Core',
|
||||||
|
'System.Net.Http',
|
||||||
];
|
];
|
||||||
|
|
||||||
var allAssemblyUrls = loadAssemblyUrls
|
var allAssemblyUrls = loadAssemblyUrls
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using WebAssembly.JSInterop;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace MonoSanityClient
|
namespace MonoSanityClient
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +31,11 @@ namespace MonoSanityClient
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void InvokeWipedMethod()
|
||||||
|
{
|
||||||
|
new HttpClientHandler();
|
||||||
|
}
|
||||||
|
|
||||||
public static string EvaluateJavaScript(string expression)
|
public static string EvaluateJavaScript(string expression)
|
||||||
{
|
{
|
||||||
var result = InternalCalls.InvokeJSUnmarshalled<string, string, object, object>(out var exceptionMessage, "evaluateJsExpression", expression, null, null);
|
var result = InternalCalls.InvokeJSUnmarshalled<string, string, object, object>(out var exceptionMessage, "evaluateJsExpression", expression, null, null);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
var ilWipeHelpersType = new TypeDefinition("ILWipe", "ILWipeHelpers",
|
var ilWipeHelpersType = new TypeDefinition("ILWipe", "ILWipeHelpers",
|
||||||
TypeAttributes.NotPublic | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit);
|
TypeAttributes.NotPublic | TypeAttributes.Class | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
|
||||||
|
moduleDefinition.TypeSystem.Object);
|
||||||
moduleDefinition.Types.Add(ilWipeHelpersType);
|
moduleDefinition.Types.Add(ilWipeHelpersType);
|
||||||
|
|
||||||
var methodAttributes =
|
var methodAttributes =
|
||||||
|
|
@ -38,6 +39,7 @@ namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
|
||||||
|
|
||||||
var notImplExceptionType = ImportEquivalentTypeFromMscorlib(moduleDefinition, typeof(NotImplementedException));
|
var notImplExceptionType = ImportEquivalentTypeFromMscorlib(moduleDefinition, typeof(NotImplementedException));
|
||||||
var notImplExceptionCtor = new MethodReference(".ctor", moduleDefinition.TypeSystem.Void, notImplExceptionType);
|
var notImplExceptionCtor = new MethodReference(".ctor", moduleDefinition.TypeSystem.Void, notImplExceptionType);
|
||||||
|
notImplExceptionCtor.HasThis = true;
|
||||||
notImplExceptionCtor.Parameters.Add(new ParameterDefinition(moduleDefinition.TypeSystem.String));
|
notImplExceptionCtor.Parameters.Add(new ParameterDefinition(moduleDefinition.TypeSystem.String));
|
||||||
|
|
||||||
var il = createMethodWipedExceptionMethod.Body.GetILProcessor();
|
var il = createMethodWipedExceptionMethod.Body.GetILProcessor();
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also resolve referenced assemblies in the same directory
|
||||||
|
if (moduleDefinition.AssemblyResolver is DefaultAssemblyResolver resolver)
|
||||||
|
{
|
||||||
|
resolver.AddSearchDirectory(Path.GetDirectoryName(inputPath));
|
||||||
|
}
|
||||||
|
|
||||||
moduleDefinition.Write(outputPath);
|
moduleDefinition.Write(outputPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure;
|
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure;
|
||||||
|
|
@ -68,6 +68,14 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
Assert.Contains("Hello from test", GetValue(Browser, "triggerExceptionMessageStackTrace"));
|
Assert.Contains("Hello from test", GetValue(Browser, "triggerExceptionMessageStackTrace"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProvidesDiagnosticIfInvokingWipedMethod()
|
||||||
|
{
|
||||||
|
Browser.FindElement(By.CssSelector("#invokeWipedMethod button")).Click();
|
||||||
|
|
||||||
|
Assert.Contains("System.NotImplementedException: Cannot invoke method because it was wiped. See stack trace for details.", GetValue(Browser, "invokeWipedMethodStackTrace"));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanCallJavaScriptFromDotNet()
|
public void CanCallJavaScriptFromDotNet()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue