Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.92k stars 442 forks source link

Debugger assemblies clash with user code assemblies #4276

Open DoubleCouponDay opened 5 years ago

DoubleCouponDay commented 5 years ago

I am attempting to start a visual studio debug session, of a V2 Functions Project, that uses System.ComponentModel.DataAnnotations Version=4.0.0.0. When I start the session, I get an exception. The log stream reads:

Exception thrown: 'System.TypeLoadException' in EntityFramework.dll
An exception of type 'System.TypeLoadException' occurred in EntityFramework.dll but was not handled in user code
Could not load type 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider' from assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

It was discovered that I am dependent on assembly file version: 4.7.2558.0 while the function core tools is dependent on assembly file version: 4.6.27207.3. I discovered this fact by looking further at the log stream from the debug session:

'func.exe' (CoreCLR: clrhost): Loaded 'C:\Users\sjsui\AppData\Local\AzureFunctionsTools\Releases\2.18.5\cli\System.ComponentModel.DataAnnotations.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

So whats happening is the debug session cannot load two versions of the assembly. The app domain of the debugger should be isolated from the app domain of the user code yet it does not appear the case.

I tried removing all my references to the standard library in favour of references to azurefunctionstools/releases, but this did not fix the issue.

environment

visual studio 15.9.7 Azure function core tools 2.18.5

DoubleCouponDay commented 5 years ago

Possible duplicate: https://github.com/Azure/azure-functions-core-tools/issues/16

ahmelsayed commented 5 years ago

@fabiocav I think this issue belongs here as I don't think the core-tools depends on System.ComponentModel.DataAnnotations itself, but I could be wrong.

fabiocav commented 5 years ago

@DoubleCouponDay do you have a repro we can look at? That would help ensure we can look at the exact issue you're running into.

DoubleCouponDay commented 5 years ago

@fabiocav

reproduce

  1. Install visual studio 2017 with the azure workload (through installer).

  2. Open vs and create a new azure function project. Select "V1 .net framework" as the target runtime.

  3. Import System.ComponentModel.DataAnnotations from the standard library.

  4. Add this class to your solution.

  5. Unload the .csproj file and change: <AzureFunctionsVersion>v1</AzureFunctionsVersion> to <AzureFunctionsVersion>v2</AzureFunctionsVersion>. Reload .csproj file.

  6. Run the solution in debug mode and wait 1 minute.

DoubleCouponDay commented 5 years ago

It looks like this is a misconfiguration in the csproj and this trail of steps is not expected behaviour for users. I think it would help this edge case if the runtime printed an error to console if the "TargetFramework" element in the .csproj does not align with the "AzureFunctionsVersion" element.

DoubleCouponDay commented 5 years ago

Just to clarify, it works when you change "AzureFunctionsVersion" element's value to V1.

fabiocav commented 5 years ago

Ah, those steps were helpful in better understanding the flow! Thank you.

Do you have a similar issue if you create a V2 project? You're not changing the target framework when you update the version (You're keeping a full framework function project targeting 2.0), correct?

DoubleCouponDay commented 5 years ago

similar issue with v2 project template

System.ComponentModel.DataAnnotations in .netcore is only available after preview 3. I'd imagine it would work.

changing the target framework when you update the version

I am not changing the target version. When you do this (net471 -> netcoreapp2.1), you need to run nuget restore in the root folder. This is because ./obj/project.settings.json prevents compilation until it has a build configuration that matches.

fabiocav commented 5 years ago

I am not changing the target version. When you do this (net471 -> netcoreapp2.1), you need to run nuget restore in the root folder. This is because ./obj/project.settings.json prevents compilation until it has a build configuration that matches.

What types are you attempting to use and having problems with? Annotations should be available in .NET Core https://apisof.net/catalog/System.ComponentModel.DataAnnotations

DoubleCouponDay commented 5 years ago

Here is the type. Notice it is not available in net core 2.2 and below.

link

fabiocav commented 5 years ago

thank you for providing this information.