c# - TypeLoadException is Not Caught by try/catch -
I'm trying to recreate a TypeLoadException
for display purposes, so my Nearly absurd library setup that looks like this:
TestProject -> The Library [1.0] \ - & gt; Proxyfor V2 - & gt; Thelibrary [2.0] get
thelibrary
version 1 in a variety of interfaces:
public interface IConsistentThing {int ConsistentProperty {; Set; }} Public Interface Evernings {int RemovedProperty {get; Set; }}
while TheLibrary
interface version look like 2:
public interface IConsistentThing {int ConsistentProperty {get ; Set; }} Public interface IShrinkingThing {}
ProxyForV2
This version of this class also applies to 2.0 IShrinkingThing
:
public class syncingimplement: Istingting ting {Public Internet Context Property; Set; }}
Then, in TestProject
, I expect to be the cause of the TypeLoadException
if someone attempts to assign ProxyForV2 Synchronizing IMAPPL
, because the first version of the interface is a property that is not enforced by another version. To prove it, I feel like a unit test:
[TestMethod] public void ShrinkingThingBreaks () {try {IShrinkingThing thing = new ProxyForV2.ShrinkingThingImpl (); The assurance.file ("This should have been a cause of exceptions"); } Hold (TypeLoadException) {// Valid}}
My problem is: This unit test fails but not my due to apprehension. File
, as I hope
dumped Test Method TestProject.LoadTester.ShrinkingThingBreaks exception: System.TypeLoadException: Method 'get_RemovedProperty' 'ProxyForV2.ShrinkingThingImpl' 'type of assembly ProxyForV2, version = 1.0 test production looks like this .0.0, culture = neutral, public keycon = zero 'is not implemented.
Then a TypeLoadException
is being thrown away and although only one place can be thrown possibly a try
block hold (Taiplodaksepshn) with
, exception is forbidden to catch
[TestMethod] public void ShrinkingThingBreaks (in) { {IShrinkingThing thing = try new ProxyForV2: Also, even if I use a catch-all, the unit tests failed with the same error as before. ShrinkingThingImpl (); The assurance.file ("This should have been a cause of exceptions"); } Hold {// valid}}
What's going on? Obviously, this is a completely conceptual scenario, but I would still like to know what is going on so that this error can be avoided or at least it can be dealt with (yes, I know that The last resort ensures that all your library versions are the same).
The worst part is that any access to all classes, such as typeof (ProxyForV2.ConsistentThingImpl)
ProxyForV2.ConsistentThingImpl.SomeStaticFunction ()
, this un-catchable TypeLoadException
causes the source of this problem when it tries to load all the squares on the net from any assignment No.
To minimize this issue, my only idea is to try to load type in different application domains so that it does not interfere, and then some crazy reflection stuff to see if the interface is implemented Compatible, but it looks like full and total overkill.
In summary: Why does it not be impossible to catch the supporter in Bellem "normal" way and how can I solve problems on runtime like this? Type itemprop = "text"> types are found before execution, execution starts with those methods which use them. To do this, you need to do the following:
[TestMethod] public void Sikuntingtingbrek () {try {InnerShrinkingThingBreaks ()} Aswasnkfail ( "It was supposed to be the cause of a kind exception"); } Hold {// valid}} [method Impl (MethodImplAttributes.NoInlining)] Private Zero InnerShrinkingThingBreaks () {IShrinkingThing = New ProxyForV2.ShrinkingThingImpl (); }
Comments
Post a Comment