You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let asms = (if toTgt then getTargetAssemblies() else getSourceAssemblies())
9121
9121
let fullName = fixName t.FullName
9122
9122
9123
-
// TODO: this linear search through all available source/target assemblies feels as if it must be too slow in some cases.
9124
-
// However, we store type translations in various tables (typeTableFwd and typeTableBwd) so perhaps it is not a problem
9125
-
let rec loop i =
9126
-
if i < 0 then
9127
-
let msg =
9128
-
if toTgt then sprintf "The design-time type '%O' utilized by a type provider was not found in the target reference assembly set '%A'. You may be referencing a profile which contains fewer types than those needed by the type provider you are using." t (getTargetAssemblies() |> Seq.toList)
9129
-
elif getSourceAssemblies() |> Seq.isEmpty then sprintf "A failure occured while determining compilation references"
9130
-
else sprintf "The target type '%O' utilized by a type provider was not found in the design-time assembly set '%A'. Please report this problem to the project site for the type provider." t (getSourceAssemblies() |> Seq.toList)
9131
-
failwith msg
9132
-
else
9133
-
match tryGetTypeFromAssembly toTgt t.Assembly.FullName fullName asms.[i] with
9134
-
| Some (newT, canSave) ->
9135
-
if canSave then table.[t] <- newT
9136
-
newT
9137
-
| None -> loop (i - 1)
9138
-
loop (asms.Count - 1)
9123
+
let bestGuess =
9124
+
asms |> Seq.tryFind(fun a -> a.FullName = t.Assembly.FullName)
9125
+
|> Option.bind(fun a -> tryGetTypeFromAssembly toTgt t.Assembly.FullName fullName a)
9126
+
9127
+
match bestGuess with
9128
+
| Some (newT, canSave) ->
9129
+
if canSave then table.[t] <- newT
9130
+
newT
9131
+
| None ->
9132
+
9133
+
// TODO: this linear search through all available source/target assemblies feels as if it must be too slow in some cases.
9134
+
// However, we store type translations in various tables (typeTableFwd and typeTableBwd) so perhaps it is not a problem
9135
+
let rec loop i =
9136
+
if i < 0 then
9137
+
let msg =
9138
+
if toTgt then sprintf "The design-time type '%O' utilized by a type provider was not found in the target reference assembly set '%A'. You may be referencing a profile which contains fewer types than those needed by the type provider you are using." t (getTargetAssemblies() |> Seq.toList)
9139
+
elif getSourceAssemblies() |> Seq.isEmpty then sprintf "A failure occured while determining compilation references"
9140
+
else sprintf "The target type '%O' utilized by a type provider was not found in the design-time assembly set '%A'. Please report this problem to the project site for the type provider." t (getSourceAssemblies() |> Seq.toList)
9141
+
failwith msg
9142
+
else
9143
+
match tryGetTypeFromAssembly toTgt t.Assembly.FullName fullName asms.[i] with
9144
+
| Some (newT, canSave) ->
9145
+
if canSave then table.[t] <- newT
9146
+
newT
9147
+
| None -> loop (i - 1)
9148
+
loop (asms.Count - 1)
9139
9149
9140
9150
and convType toTgt (t:Type) =
9141
9151
let table = (if toTgt then typeTableFwd else typeTableBwd)
9142
9152
match table.TryGetValue(t) with
9143
9153
| true, newT -> newT
9144
9154
| false, _ ->
9145
-
if t :? ProvidedTypeSymbol && (t :?> ProvidedTypeSymbol).IsFSharpTypeAbbreviation then t
9155
+
let isSymbol = t :? ProvidedTypeSymbol
9156
+
if isSymbol && (t :?> ProvidedTypeSymbol).IsFSharpTypeAbbreviation then t
9146
9157
// Types annotated with units-of-measure
9147
-
elif t :? ProvidedTypeSymbol && (t :?> ProvidedTypeSymbol).IsFSharpUnitAnnotated then
9158
+
elif isSymbol && (t :?> ProvidedTypeSymbol).IsFSharpUnitAnnotated then
9148
9159
let genericType = t.GetGenericTypeDefinition()
9149
9160
let newT = convTypeRef toTgt genericType
9150
9161
let typeArguments = t.GetGenericArguments() |> Array.map (convType toTgt) |> Array.toList
0 commit comments