Fody / AsyncErrorHandler

An extension for Fody to integrate error handling into async and TPL code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Got exception during compile: Cannot cast from source type to destination type.

yozzozo opened this issue · comments

I added AsyncErrorHandler to my PCL project in Xamarin Studio via nuget. I added it to my FodyWeavers.xml with the following line: and tried to compile the PCL project. I have this in place in my MyProject.CorePCL.Services namespace (didn't know where else to put it):

public static class AsyncErrorHandler
{
    public static void HandleException(Exception exception)
    {
        Mvx.Exception("Exception occurred: " + exception.Message);
    }
}

I got the following exception during compile:

Error: Fody: An unhandled exception occurred:
Exception:
Cannot cast from source type to destination type.
StackTrace:
at MethodProcessor.Process (Mono.Cecil.MethodDefinition) <0x00237>
at ModuleWeaver.Execute () <0x001cb>
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,object) <0x0002f>
at InnerWeaver.ExecuteWeavers () <0x00200>
at InnerWeaver.Execute () <0x000db>

Source:
AsyncErrorHandler.Fody
TargetSite:
Void Process(Mono.Cecil.MethodDefinition)
 (MyProject.CorePCL)

any ideas?

can u remove fody and upload the resultant dll somewhere

I can do that, and email you as an attachment or a link. Is it enough to comment out all the weavers in FodyWeavers.xml, or do I need to actually remove the Fody package?

u need to remove the package. my email is simon.cropp@gmail.com

Sent

what versions of Fody and AsyncErrorHandler are you using?

aslo i have deployed 1.0.10 to nuget with some extra error handling. can you try that and tell me if u get a different error

I was using 1.0.9.0.
After updating to 1.0.10.0, I get this error:

error : Fody: An unhandled exception occurred:
Exception:
Failed to process 'MYPROJECTNAME.Core.Services.MockServerDataService/<CallAsync>c__async0`1'.
StackTrace:
at ModuleWeaver.Execute () <0x002ab>
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,object) <0x0002f>
at InnerWeaver.ExecuteWeavers () <0x00200>
at InnerWeaver.Execute () <0x000db>

Source:
AsyncErrorHandler.Fody
TargetSite:
Void Execute()
Expected VariableDefinition but got 'MethodReference'.
StackTrace:
  at MethodProcessor.Process (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 
  at ModuleWeaver.Execute () [0x00000] in <filename unknown>:0 
Source:
AsyncErrorHandler.Fody
TargetSite:
Void Process(Mono.Cecil.MethodDefinition)

FYI in that method it's trying to process, it does something like this:

try { await Task.Delay(foo);  await Task.Run(() => ... ); }
catch (Exception e) { ... }

still cant repro this

tried

public async Task MethodWithTryCatch()
{
    try
    {
        await Task.Delay(1);
        await Task.Run(() => Bar());
    }
    catch (Exception e)
    {
    }
}

void Bar()
{
}

and it works

can u upload a sample project that reproduces the issue

Hi, I have an update on this issue. My FodyWeavers looked like this, and it caused the exception:

<PropertyChanged EventInvokerNames="raisePropertyChanged"/>
<NullGuard ExcludeRegex="Validation"/>
<AsyncErrorHandler/>

I moved AsyncErrorHandler to the TOP of the file, and it fixed the issue! Hopefully this gives you some ideas on what's wrong...

Please upload a repro for this issue.