Skip to content

Fix 82: Scope of types for named values in attributes #568

Closed
dsyme wants to merge 5 commits intodotnet:OOBfrom
dsyme:fix-82
Closed

Fix 82: Scope of types for named values in attributes #568
dsyme wants to merge 5 commits intodotnet:OOBfrom
dsyme:fix-82

Conversation

@dsyme
Copy link
Copy Markdown
Contributor

@dsyme dsyme commented Aug 4, 2015

Moving to OOB, see #437

@dsyme
Copy link
Copy Markdown
Contributor Author

dsyme commented Aug 4, 2015

I've verified the fix against the @vladima test gist https://gist.github.com/vladima/4f1b6c248ec21ff45fa1 described here: #437 (comment) by hand.

What I did:

csc /target:library program.cs     
fsc.exe -a ProvidedTypes.fs mirror.fs  // use an F# 4.0 compiler for this

then compare

path-to-new-fsharp\fsc.exe -r mirror.dll -o client.exe -r:System.ServiceModel.dll client.fs

path-to-fsharp4\fsc.exe -r mirror.dll -o client2.exe -r:System.ServiceModel.dll client.fs

for the modified client.fs below. The first client.exe succeeds and prints "Sign", the second client2.exe fails with an exception because the custom attribute metadata was mangled

module Client

type T = Top.Repro.C
T.Run()

let attrs = typeof<T>.GetMethod("Run").GetCustomAttributes(false)
let attr = attrs.[0] :?> System.ServiceModel.FaultContractAttribute

printfn "%A" (attr.ProtectionLevel.ToString())

@latkin yes, could you please add this as a test when you integrate. Thanks...!!!

@latkin latkin added this to the F# 4.0 Update 1 milestone Aug 13, 2015
@latkin
Copy link
Copy Markdown
Contributor

latkin commented Aug 13, 2015

When I try the test scenario, it works in F# 3.1, pre-fix 4.0, and post-fix 4.0.

C:\Users\latkin
> csc /target:library .\library.cs
Microsoft (R) Visual C# Compiler version 12.0.31010.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\latkin
>  & 'C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\Fsc.exe' -a  .\providedtypes.fs .\mirror.fs
Microsoft (R) F# Compiler version 12.0.40226.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

C:\Users\latkin
> & 'C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\Fsi.exe' .\client.fsx
In run
"Sign"

library.cs (note - needed to mark C 'public' or else all F# versions had runtime crash)

using System;
using System.Net.Security;
using System.ServiceModel;

public class C {
    [FaultContract(typeof(Exception), ProtectionLevel = ProtectionLevel.Sign)]
    public static void Run() { Console.WriteLine("In run");}
}

mirror.fs

// compile as: fsc --target:library ProvidedTypes.fsi ProvidedTypes.fs Mirror.fs
namespace Repro

open System.IO
open System.Reflection
open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices

[<assembly : TypeProviderAssembly>]
do()

[<TypeProvider>]
type Mirror() as this =
    inherit TypeProviderForNamespaces()
    let thisAssembly = typeof<Mirror>.Assembly
    let topType = ProvidedTypeDefinition(thisAssembly, "Top", "Repro", Some typeof<obj>, IsErased = true)
    let csAssembly = 
        let location = Path.GetDirectoryName(thisAssembly.Location)
        System.Reflection.Assembly.LoadFrom(Path.Combine(location, "library.dll"))
    do topType.AddAssemblyTypesAsNestedTypesDelayed(fun() -> csAssembly)
    do this.AddNamespace("Top", [topType])

client.fsx

#r "./mirror.dll"
#r "System.ServiceModel.dll"

type T = Top.Repro.C
T.Run()

let attrs = typeof<T>.GetMethod("Run").GetCustomAttributes(false)
let attr = attrs.[0] :?> System.ServiceModel.FaultContractAttribute

printfn "%A" (attr.ProtectionLevel.ToString())

@latkin
Copy link
Copy Markdown
Contributor

latkin commented Aug 13, 2015

Mmm ok repro only occurs in the context of an exe, it doesn't repro in FSI.

@dsyme dsyme closed this in 4385bb7 Aug 14, 2015
@latkin latkin added the fixed label Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants