nic*_*las 4 dll f# visual-studio type-providers
在构造提供类型的内部表示时,我间接地在引号中调用我的类型的内部表示,另一个dll,我的代码可以修改.
目前,当我使用类型提供程序时,告诉我它找不到这样的dll:
"无法加载文件或程序集xxxx或其依赖项之一"
但是,当我使用Process Explorer检查VS时,我可以看到dll XXX已加载...有没有什么可以让引号中的代码接受来自外部dll的代码?
**更新**
我尝试了一个简化的例子,似乎可以调用这样的外部DLL而无需做任何特殊的事情.在我的情况下,所有dll XXX依赖于加载,我在Process explorer以及模块窗口中看到它们,当我调试devenv.exe本身....
我不知道在哪里看.这是内在的例外.
**更新**
如果我在这个路径之一复制xxx dll及其依赖项,编译器工作正常.我仍然想知道什么可以触发devenv.exe正确显示它们已加载但无法访问.
=== Pre-bind state information ===
LOG: User = xxx\Administrator
LOG: DisplayName = bloombergapi, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Administrator\AppData\Local\Microsoft\VisualStudio\11.0\devenv.exe.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/bloombergapi/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/PublicAssemblies/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/PublicAssemblies/bloombergapi/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/PrivateAssemblies/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/PrivateAssemblies/bloombergapi/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/bloombergapi/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/CommonExtensions/Platform/Debugger/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/CommonExtensions/Platform/Debugger/bloombergapi/bloombergapi.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/PrivateAssemblies/DataCollectors/bloombergapi.DLL.
Run Code Online (Sandbox Code Playgroud)
...
回答
似乎不可能从另一个库中调用一个以Type作为参数的函数.联合类型有效,但不适合类型......如下所示
--Library.dll
namespace Library
module SampleModule =
type LocalUnion = | LocalUnion of int
type Localtype() =
member x.value = 2
Run Code Online (Sandbox Code Playgroud)
--LibraryTP.dll
namespace LibraryTP
module Module =
open System.Reflection
open Samples.FSharp.ProvidedTypes
open FSharpx.TypeProviders.DSL
open Microsoft.FSharp.Core.CompilerServices
let f a =
Library.SampleModule.sampleFunction a a
let g (a:Library.SampleModule.LocalUnion) =
let (Library.SampleModule.LocalUnion(v)) = a
v
let ftype (a:Library.SampleModule.Localtype) =
a.value
let createTP ns =
erasedType<obj> (Assembly.GetExecutingAssembly()) ns "Outside"
|> staticParameter "file"
(fun typeName (parameterValues:string) ->
erasedType<obj> (Assembly.GetExecutingAssembly()) ns typeName
|+!> ( provideProperty
"test" //OK
typeof<float>
(fun args -> <@@ g ( f 2 ) @@>)
|> makePropertyStatic
)
|+!> ( provideProperty
"test2" //KO
typeof<int>
(fun args -> <@@ ftype ( Library.SampleModule.Localtype()) @@>)
|> makePropertyStatic
)
)
[<TypeProvider>]
type public CustomTypeProvider(cfg:TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()
do this.AddNamespace("TP", [createTP "TP"])
[<TypeProviderAssembly>]
do()
Run Code Online (Sandbox Code Playgroud)
--Program.fs
type sampleValue = TP.Outside<"">
[<EntryPoint>]
let main(args) =
let t = sampleValue.Test //OK
let tt = sampleValue.Test2 //KO
Run Code Online (Sandbox Code Playgroud)
des*_*sco 10
您的程序集可能会加载到不同的绑定上下文中.当反序列化引号时,它可能会尝试将程序集加载到一个绑定上下文,即使程序集已加载到另一个上下文,此尝试也可能失败.作为类型提供程序设计时程序集中的变通方法,您可以向AssemblyResolve事件添加处理程序,并尝试在已加载程序集的列表中查找目标程序集.
do System.AppDomain.CurrentDomain.add_AssemblyResolve(fun _ args ->
let name = System.Reflection.AssemblyName(args.Name)
let existingAssembly =
System.AppDomain.CurrentDomain.GetAssemblies()
|> Seq.tryFind(fun a -> System.Reflection.AssemblyName.ReferenceMatchesDefinition(name, a.GetName()))
match existingAssembly with
| Some a -> a
| None -> null
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
847 次 |
| 最近记录: |