xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

System.IO.FileNotFoundException: 'Could not load file or assembly 'clrcompression, Culture=neutral, PublicKeyToken=null'. Das System kann die angegebene Datei nicht finden.' #5471

Open MagicAndre1981 opened 5 years ago

MagicAndre1981 commented 5 years ago

Description

When I run my App in debug mode and configured VS2017 to stop at System.IO.FileNotFoundException I get the exception with message:

'Could not load file or assembly 'clrcompression, Culture=neutral, PublicKeyToken=null'

Steps to Reproduce

  1. create a new Xamarin.Forms app
  2. configure VS to stop at System.IO.FileNotFoundException
  3. launch the app

Expected Behavior

app runs without any issue

Actual Behavior

debugger stop in UWP app in app.cs at protected override void OnLaunched(LaunchActivatedEventArgs e) at line Xamarin.Forms.Forms.Init(e)

System.Private.CoreLib.dll!System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName assemblyRef, System.Reflection.RuntimeAssembly reqAssembly, ref System.Threading.StackCrawlMark stackMark, System.IntPtr pPrivHostBinder, bool throwOnFileNotFound, System.IntPtr ptrLoadContextBinder) Line 362   C#
    System.Private.CoreLib.dll!System.Reflection.Assembly.Load(System.Reflection.AssemblyName assemblyRef) Line 167
Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.GetAssemblies() Line 63   
Xamarin.Forms.Core.dll!Xamarin.Forms.Internals.Registrar.RegisterAll(System.Type[] attrTypes) Line 253
    Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Forms.Init(Windows.ApplicationModel.Activation.IActivatedEventArgs launchActivatedEventArgs, System.Collections.Generic.IEnumerable<System.Reflection.Assembly> rendererAssemblies) Line 61    
    foo.App.UWP.exe!foo.App.UWP.App.OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs e)

Basic Information

Screenshots

image

Reproduction Link

MagicAndre1981 commented 5 years ago

There is no need for repro, it happens to all users with blank app. It was reported some time ago in old bugtracker, but still occurs.

A workaround is to configure VS to not stop at this exception, but this may hide other issues later in my code.

MagicAndre1981 commented 5 years ago

The source where the issue occurs is here.

Here IOException and BadImageFormatException are catched and ignored. So maybe also catch FileNotFoundException here or check for clrcompression and skip loading it.

kingces95 commented 5 years ago

Feature request for Just-My-Code debugging.

jamie-lord commented 5 years ago

Yeah, I'm getting the same issue. Very strange behaviour. The UWP project was working fine and then suddenly, this started occurring but I can't find a way to stop it from happening.

MagicAndre1981 commented 5 years ago

@jamie-lord

in exception settings uncheck to stop at System.IO.FileNotFoundException

image

yschang commented 5 years ago

I had the same issue as well and fixed it. I was able to fix the issue by:

Properties -> Build -> Enable "Compile with .NET Native tool chain"

MagicAndre1981 commented 5 years ago

@yschang nope, still the same issue, also native runtime has a clrcompression.dll

yschang commented 5 years ago

Can you try it on Visual Studio 2019? Also, can you update all of your Nuget packages from your UWP project?

MagicAndre1981 commented 5 years ago

I now no longer get missing clrcompression.dll, now VS stops with Could not load file or assembly 'Microsoft.Graphics.Canvas, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'Microsoft.Graphics.Canvas, Culture=neutral, PublicKeyToken=null'. Das System kann die angegebene Datei nicht finden.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder) in E:\A\_work\414\s\src\mscorlib\src\System\Reflection\RuntimeAssembly.cs:line 353

and missing ucrtbased.dll

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'ucrtbased, Culture=neutral, PublicKeyToken=null'. Das System kann die angegebene Datei nicht finden.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder) in E:\A\_work\414\s\src\mscorlib\src\System\Reflection\RuntimeAssembly.cs:line 353

But both can be found in C:\Users\USERNAME\AppData\Local\DevelopmentFiles\Foo.App.UWPVS.Debug_x86.USERNAME

🤔 🤷‍♂️

MagicAndre1981 commented 5 years ago

I also get this one now after updating to 4.3.0.947036 at Xamarin.Forms.Forms.Init(e);

System.TypeLoadException
  HResult=0x80131522
  Message=Error 0x261F.  Debugging resource strings are unavailable. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.30319.0&File=mscorrc.dll&Key=0x261F 
  Source=System.Private.CoreLib
  StackTrace:
   at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)

Inner Exception 1:
COMException: Klasse nicht registriert (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

🤔 🤷‍♂️

MagicAndre1981 commented 5 years ago

I now also get a System.IO.FileNotFoundException in Xamarin.Forms.Platform.UAP.dll without any details:

Exception thrown: 'System.IO.FileNotFoundException' in Xamarin.Forms.Platform.UAP.dll
Das System kann die angegebene Datei nicht finden. (Exception from HRESULT: 0x80070002)

And this is the stack

image

SmartmanApps commented 4 years ago

Thank you! This fixed it for me! :-)

I had the same issue as well and fixed it. I was able to fix the issue by:

Properties -> Build -> Enable "Compile with .NET Native tool chain"

eveselov commented 4 years ago

I am having the same issue. The suggestion to enable "Compile with .NET Native tool chain" did not help.

a-einstein commented 4 years ago

I am having the same error about Microsoft.Graphics.Canvas, and it is driving me NUTS. It is the first dll mentioned in a list of Extensions in AppX\AppxManifest.xml, and the dll is actually THERE. I have also checked System.IO.Directory.GetCurrentDirectory(), which is THERE. It crashes at the mentioned Xamarin.Forms.Forms.Init(e).

I tried Compile with .NET Native tool chain, but that did not even compile.

Frustrating is that newly created Xamarin solution including an UWP target DOES run, having exactly the same list of extensions. I have been comparing the references, the project files, UWP\Package.appxmanifest, and AppX\AppxManifest.xml. None of that brought me any further.

PureWeen commented 4 years ago

This is just a first chance exception you're seeing. It's a byproduct of assembly scanning but it shouldn't crash the application

Is your application failing to launch?

PureWeen commented 4 years ago

@a-einstein it sounds like your exception is different than what is posted here. Can you create a new issue? @jsuarezruiz FYI

a-einstein commented 4 years ago

PureWeen, if you are addressing me: yes it crashes on the Canvas, followed by ucrtbased, and then a lot of 'EventLog access is not supported on this platform.'

And my situation is very similar to ones mentioned previously. Read the details.

RuddyOne commented 3 years ago

Any updates on this?

MagicAndre1981 commented 3 years ago

Any updates on this?

I disabled the debugger to stop at System.IO.FileNotFoundException and ignore the message in VS output. In MAUI, UWP get replaced with WinUI3, so they don't care about UWP any longer.

SmartmanApps commented 3 years ago

Hello. I've just had this issue re-appear with latest version of VS2019 and Xamarin Forms (2083). "Message=Could not load file or assembly 'Microsoft.Graphics.Canvas, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified". The previous work-around of enable native tool chain not working.

The thing is, I created a new app to test some of my library pages (as it first happened when trying to add one of my library pages - the page only had a label in it so far, so shouldn't have been any issue). I did this because the issue then started happenning with some of my other pages which I hadn't touched. So I created this test app, and first few pages I added to it worked, then I struck one that wasn't working, and none of the rest worked either. Then I went back to one which had been working, and it wasn't working anymore either! It even crashes now on a page which is in the same project. It looks like something happens to corrupt things in your project, and then you're stuck. Doing a clean didn't fix it.

SmartmanApps commented 3 years ago

Found a solution at https://stackoverflow.com/questions/58346806/xamarin-microsoft-netcore-universalwindowsplatform-v6-2-9-fails - delete the .vs folder! For the libraries, I had to delete their .vs folder too.

MagicAndre1981 commented 3 years ago

Found a solution at https://stackoverflow.com/questions/58346806/xamarin-microsoft-netcore-universalwindowsplatform-v6-2-9-fails - delete the .vs folder! For the libraries, I had to delete their .vs folder too.

NO, this only resets the VS options for the solution and removes the exception settings so that VS no longer breaks at the the FileNotFoundException.

SmartmanApps commented 3 years ago

Found a solution at https://stackoverflow.com/questions/58346806/xamarin-microsoft-netcore-universalwindowsplatform-v6-2-9-fails - delete the .vs folder! For the libraries, I had to delete their .vs folder too.

NO, this only resets the VS options for the solution and removes the exception settings so that VS no longer breaks at the the FileNotFoundException.

No. After reading your comment I had a look. I can see that you're partly right in that there is still one FileNotFound Exception there, HOWEVER, it's NOT the one that was causing my app to crash. The only exception there now, having deleted the .vs folder, is "Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll", and that wasn't the one causing my app to crash, so it's not clearing ALL FileNotFound exceptions, but it's clearing the one which was causing the crash (the Microsoft.Graphics.Canvas one). Why it's doing that is another matter, but that is definitely what is happenning on my machine (it's also solved another issue I had on my machine which had a different error message - couldn't find my library that I had linked to. After deleting the .vs folder it now finds it. As per the comment in that StackOverflow issue "causing random runtime library resolution problem", and it's definitely random, cos it's now solved 2 different error messages for me... and there's a 3rd I'm going to try again tonight to see if it solves that one too).

BTW interesting twist, when I checked to break on FileNotFoundException, that made the app-crashing exception (the Canvas one) come back!

P.S. to be clear, when I say crash, I mean crash. Not "break at exception". With break at exception unchecked, my app will crash with the Canvas not found exception message (or another exception message). Deleting .vs folders clears it and app works again.

SmartmanApps commented 3 years ago

@PureWeen

This is just a first chance exception you're seeing. It's a byproduct of assembly scanning but it shouldn't crash the application

Is your application failing to launch?

That's an interesting comment that you mention first chance exceptions, as I have code in my app to catch those (i.e. AppDomain.CurrentDomain.FirstChanceException+=CurrentDomain_FirstChanceException;), so I investigated some more. When I check break on exception, my code does catch all those first chance exceptions, but when I uncheck break on exception they are no longer there! I would've expected them to still be there regardless of break checked/unchecked in VS, but they seem to appear only when break is checked.

RayKoopa commented 3 years ago

Just wasted a week because of this bogus FileNotFoundException: '' occurring when an actual other exception is being thrown. The call stack always seems to show an attempted load of satellite / localization assemblies, possibly looking up an error text or something similarly stupid, which fails.

I almost gave up on the whole .NET 6.0 / Xamarin stuff again until I realized I have to press F5 one or more times until I get the actual exception.

It only occurs on a real device and not the emulator for me.

dsaf commented 1 year ago

Just wasted a week because of this bogus FileNotFoundException: '' occurring when an actual other exception is being thrown. The call stack always seems to show an attempted load of satellite / localization assemblies, possibly looking up an error text or something similarly stupid, which fails.

I almost gave up on the whole .NET 6.0 / Xamarin stuff again until I realized I have to press F5 one or more times until I get the actual exception.

It only occurs on a real device and not the emulator for me.

@RayKoopa damn bro, thank you! This System.IO.FileNotFoundException: '' forced me to write code just for debugging. As you can see - still not fixed.