Skip to content

MethodNotFoundException in net8 #96268

Closed

Description

@heckl

Description

public static List<int> Test1No(Worksheet sourceSheet) 
{
    return new List<int>();
}
public static int Test2Yes(Worksheet sourceSheet) 
{
    return 3;
}
public static List<int> Test3Yes() 
{
    return new List<int>();
} 

MethodNotFoundException occurs if there is a Worksheet (office.interop) parameter and a List return value. So version 2 and 3 works but not version 1. These methods are called from sperate project but both projects were .net 8. My workaround was going back to .net7.

Reproduction Steps

https://www.dropbox.com/scl/fi/mf20wxeqju9ghhm34z4td/TestSolution.zip?rlkey=8et27m0vgb6v2kpjg3j7ach84&dl=0

I created a solution to demonstrate the problem. You can build the solution but you will get the exception in runtime.

Expected behavior

There should be no exception at runtime.

Actual behavior

There is a MethodNotFoundException in runtime.

Regression?

If you go back to .net7 it works fine.

Known Workarounds

Go back .net7

Configuration

.net8
Windows 10
x64

Other information

No response

Activity

  1. ghost added
    untriaged
    on Dec 22, 2023
  2. ghost added
    needs-area-label
    on Dec 22, 2023
  3. removed
    needs-area-label
    on Dec 22, 2023
  4. added this to the 9.0.0 milestone on Jan 2, 2024
  5. ghost removed
    untriaged
    on Jan 2, 2024
  6. heckl commented on Jan 3, 2024

    @heckl
    Author

    Hi, I see the issue is added to the 9.0.0 milestone. Do you know a workaround so on .net 8?

  7. AaronRobinsonMSFT commented on Jan 3, 2024

    @AaronRobinsonMSFT
    Member

    @heckl This hasn't been investigated yet so there isn't any action at present. The description indicates that we need to look into it and once we have an understanding we will be able to define next steps.

  8. ivanch commented on Jan 3, 2024

    @ivanch

    Hello guys!
    I did take a look at this but I wasn't able to get as far to a solution, but I did find a few things:

    • This also happens when using other classes from System.Collections.Generic namespace, e.g. Queue<T>, HashSet<T>, LinkedList<T>, SortedSet<T> and Stack<T>. More importantly, I did find that it also happens if you declare a new class, say TestT<T> internally and use it to return the value;
    • This doesn't happen when using an interface as the return type, so if you put IList<T> as return type and do return new List<T> it works perfectly. Same thing with the internal class I mentioned above, if we declare an interface ITestT<T> and use it, it doesn't crash;
    • This only occurs when dealing with an external library, like when having multiple projects as the issue states, and not if the method is internal to the binary;
    • This does not occur if you use reflection to call the method, the following also works as expected: typeof(TestClass).GetMethod("Test1No", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Invoke(null, new object[] { null });.

    I also was able to find this stack trace with Windbg:

    [0x0]   KERNELBASE!RaiseException+0x69   0x738517bc30   0x7ffaaf5ca3f7   
    [0x1]   coreclr!RaiseTheExceptionInternalOnly+0x26b(Object * throwable = 0x738517db70, int rethrow = 167772185, fForStackOverflow = <unavailable>)   0x738517bd10   0x7ffaaf5f2d20   
    [0x2]   coreclr!UnwindAndContinueRethrowHelperAfterCatch+0x38(Exception * pException = 0x1c1ff05fc20, pEntryFrame = <unavailable>)   0x738517be20   0x7ffaaf65fb85   
    [0x3]   coreclr!CEEInfo::resolveToken+0x175ee5(CORINFO_RESOLVED_TOKEN * pResolvedToken = 0x738517c270)   0x738517be60   0x7ffaae3305bc   
    [0x4]   clrjit!Compiler::impImportBlockCode+0x2cc(BasicBlock * block = 0x1c1ff04c118 : BB2; BBJ_RETURN)   0x738517c170   0x7ffaae32f562   
    [0x5]   clrjit!Compiler::impImportBlock+0x62(BasicBlock * block = 0x1c1ff04c118 : BB2; BBJ_RETURN)   0x738517c960   0x7ffaae32f245   
    [0x6]   clrjit!Compiler::impImport+0x485()   0x738517ca70   0x7ffaae3d1f6e   
    [0x7]   clrjit!Compiler::fgImport+0xe()   0x738517cb00   0x7ffaae3c4a92   
    [0x8]   clrjit!Phase::Run+0x1b()   0x738517cb30   0x7ffaae32daeb   
    [0x9]   clrjit!DoPhase+0x49()   0x738517cb30   0x7ffaae32daeb   
    [0xa]   clrjit!Compiler::compCompile+0x182(void * * methodCodePtr = 0x738517d740, unsigned int * methodCodeSize = 0x738517d7f8 : 0x1, JitFlags * compileFlags = 0x738517d760)   0x738517cb30   0x7ffaae32daeb   
    [0xb]   clrjit!Compiler::compCompileHelper+0x34b(classPtr = <unavailable>, ICorJitInfo * compHnd = 0x738517db70, CORINFO_METHOD_INFO * methodInfo = 0x738517da60, void * * methodCodePtr = 0x738517d740, unsigned int * methodCodeSize = 0x738517d7f8 : 0x1, JitFlags * compileFlags = 0x738517d760, JitFlags * compileFlags = 0x738517d760)   0x738517d380   0x7ffaae32cede   
    [0xc]   clrjit!Compiler::compCompile+0x24e(CORINFO_MODULE_STRUCT_ * classPtr = 0x7ffa4fb2e0a0, CORINFO_MODULE_STRUCT_ * classPtr = 0x738517da60, void * * methodCodePtr = 0x738517d740, void * * methodCodePtr = 0x738517da60, unsigned int * methodCodeSize = 0x738517d7f8 : 0x1, unsigned int * methodCodeSize = 0x7ffa4fb58da8 : 0x60400, JitFlags * compileFlags = 0x738517d760)   0x738517d460   0x7ffaae385f45   
    [0xd]   clrjit!jitNativeCode+0x265(CORINFO_METHOD_STRUCT_ * methodHnd = 0x7ffa4fb500c0, CORINFO_MODULE_STRUCT_ * classPtr = 0x7ffa4fb2e0a0, ICorJitInfo * compHnd = 0x738517db70, ICorJitInfo * compHnd = 0x738517db70, CORINFO_METHOD_INFO * methodInfo = 0x738517da60, CORINFO_METHOD_INFO * methodInfo = 0x738517da60, void * * methodCodePtr = 0x738517d740, unsigned int * methodCodeSize = 0x738517d7f8 : 0x1, JitFlags * compileFlags = 0x738517d760, inlineInfoPtr = <unavailable>)   0x738517d560   0x7ffaae3d6f76   
    [0xe]   clrjit!CILJit::compileMethod+0xa6(ICorJitInfo * compHnd = 0x738517db70, CORINFO_METHOD_INFO * methodInfo = 0x738517da60, unsigned int flags = 0x80000004, unsigned char * * entryAddress = 0x738517d808, unsigned char * * entryAddress = 0x738517d808, unsigned int * nativeSizeOfCode = 0x738517d7f8 : 0x1, unsigned int * nativeSizeOfCode = 0x738517d7f8 : 0x1)   0x738517d700   0x7ffaaf529ed6   
    

    Hope this helps a little.

  9. tombycz commented on Jan 31, 2024

    @tombycz

    Hello,
    this is probably caused by any use of generics in the output, I encountered the same issue with the method

    int? GetNumber(Worksheet sheet, string rangeName)

  10. ghost added
    in-pr
    on Feb 9, 2024
  11. ghost removed
    in-pr
    on Feb 9, 2024
  12. ghost added
    in-pr
    on Feb 9, 2024
  13. ghost removed
    in-pr
    on Feb 12, 2024
  14. elinor-fung commented on Mar 13, 2024

    @elinor-fung
    Member

    The fix for this is in the 8.0.3 release (and main). Thanks all for the report, repro, and investigation!

  15. locked and limited conversation to collaborators on Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions