未找到类型或命名空间。 C# +甲骨文
Edit3:很抱歉不断进行编辑,我确信有一项法律规定,只有在您公开请求解决方案后才能取得进展。
我已经在 Reflector 中打开了 oracle 程序集。该程序集包含对 v1.0.3705 mscorlib 和 2.0.0.0 mscorlib 的引用...
它还引用了面向 v1.0.3705 运行时的 Common.Logging 程序集。
这让我觉得很奇怪。有人曾经见过这样的事情吗?
Edit2:好的,创建了一个针对 3.5 的 WPF 应用程序。引用了我的 API 库,添加了一行来调用声明 Oracle 库中声明的接口类型变量的代码,一切正常。
因此,该问题仅出现在 Framework 4 应用程序中。这对我来说有一定的意义,因为 3.5 本质上是 2 加上一些额外的库。但我现在很困惑为什么我可以在我的 4 项目中引用 2 程序集并使用它的类型,而不是这个 Oracle 程序集,并且出现一个无用的错误。
编辑:似乎是框架版本的问题。我很惊讶我以前没有遇到过这样的事情。
这是新的情况: 向 Framework 2 添加了新的 Windows 窗体应用程序集。 使用路径在 GAC 中添加了对 Coherence DLL 的引用(它从未出现在程序集下的引用中,这很糟糕吗?)。
添加了带有“INamedCache 缓存;”行的按钮就是这样。编译并运行。一切正常。
第 2 步,删除对一致性的引用,添加对我原始 API 的引用。编译,一切正常。请记住,API 只是运行上面的代码行。
现在,如果我将 Windows 窗体应用程序的引用添加到我的 WPF 应用程序,并创建一个 Form1,那么所有 IntelliSense 都会正常工作,但是当您编译时,它会给出“未找到类型或命名空间”。
再次删除“INamedCache 缓存;”来自表单应用程序中的 Form1(仍由 WPF 应用程序引用),并且所有内容都会再次编译。
因此,我的 WPF Framework 4 应用程序将使用我的 Framework 2 Windows Forms 应用程序(当然还添加了 Forms 2 引用),但如果该 Forms 应用程序包含对 Oracle 库的引用并声明了在该库中声明的接口类型的变量。繁荣,瞬间失败。
原始帖子在这里:
Visual Studio 2010。
我有一个 WPF Windows 应用程序项目和一个类库。该类库引用了 Oracle 的 Coherence for .NET 程序集。类库有一个类和一个方法,该方法声明一个接口类型的变量。
WPF 应用程序有一个调用此方法的按钮。智能感知工作正常。
当我尝试编译时,出现旧的“找不到名为‘WhyAreYouNotWorking’的类型或命名空间”错误。我有一个可以运行的演示项目,我已将引用从一个项目复制到另一个项目,但没有成功。我添加了对任何支持程序集的引用。
另外,
public void Test()
{
INamedCache cache;
//CacheFactory.SetCacheFactoryConfig("coherence.xml");
//CacheFactory.SetCacheConfig("cache-config.xml");
//CacheFactory.SetPofConfig("pof-config.xml");
//INamedCache cache = CacheFactory.GetCache("ians-cache");
//Console.WriteLine(cache.CacheName);
}
在上面您可以看到我的类库中的一种方法。该库将顺利编译所有注释或未注释的行。仅当我删除所有行时,WPF 应用程序才会编译。
因此,这里的问题是,如果类库包含 Coherence Oracle .net 程序集中包含的代码,则 WPF 应用程序将不会使用对类库的引用进行编译。
我很困惑。有点尴尬和困惑:)
Edit3: Sorry for the constant edits, I'm sure there's a law which states progress is only made once you've publicly requested a solution.
I've opened the oracle assembly in Reflector. The assembly includes a reference to the both the v1.0.3705 mscorlib AND the 2.0.0.0 mscorlib...
It also references a Common.Logging assembly which targets the v1.0.3705 runtime.
This strikes me as at best odd. Anyone ever seen something like this before?
Edit2: Ok, created a WPF application against 3.5. Referenced my API library, added a line to call the code that declares a variable of an interface type declared in the Oracle library and it all works.
So the problem only occurs with Framework 4 applications. This makes a certain amount of sense to me as 3.5 is essentially 2 with some extra libraries. But I'm now confused as to why I can reference a 2 assembly in my 4 project and use its types, just not this Oracle one, and with an unhelpful error.
Edit: Seems to be an issue with the framework version. I'm suprised I haven't encountered something like this before.
Here's the new situation:
Added new Windows forms application set to Framework 2.
Added reference to Coherence DLL in GAC (It never appears in references under assemblies, is that bad?) using path.
Added button with line "INamedCache cache;" That's it. compiled and run. All works fine.
Step 2, remove reference to coherence, add reference to my original API. Compile, all works fine. Remember the API is just running the line of code above.
Now, if I add a reference to the Windows forms application to my WPF application, and create a Form1, again, all the IntelliSense works, but when you compile it gives a "type or namespace not found".
Again, remove the "INamedCache cache;" from the Form1 in the forms application (still referenced by the WPF application) and it all compiles again.
So my WPF Framework 4 application will consume my framework 2 windows forms application (with Forms 2 reference added of course) but if that forms application contains a reference to the oracle library AND declares a variable of an interface type declared in that library. boom, instant failure.
Original post here:
Visual Studio 2010.
I have a WPF windows app project and a class library. The class library references Oracle's Coherence for .NET assembly. The class library has one class with one method which declares a variable of an interface type.
The WPF application has a button which calls this method. IntelliSense works fine.
When I try to compile I get the old "The type or namespace named 'WhyAreYouNotWorking' could not be found" error. I have a demo project which does run, I've copied the references from one to the other with no luck. I've added references to any supporting assemblies.
Also
public void Test()
{
INamedCache cache;
//CacheFactory.SetCacheFactoryConfig("coherence.xml");
//CacheFactory.SetCacheConfig("cache-config.xml");
//CacheFactory.SetPofConfig("pof-config.xml");
//INamedCache cache = CacheFactory.GetCache("ians-cache");
//Console.WriteLine(cache.CacheName);
}
Above you see the one method in my class lib. This lib will compile happily with all those lines commented or uncommented. The WPF application will only compile if I rem out ALL the lines.
So the problem here is the WPF application will not compile with a reference to the class library, if the class library includes code contained in the Coherence Oracle .net assembly.
I'm baffled. Slightly embarrassed and baffled :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,也许复制到参考属性中的输出目录?
Hmmm, copy to output directory in the reference properties maybe?
明白了。
WPF 4.0 应用程序默认为“.NET Framework 4 Client Profile”。将其切换到“.NET Framework 4”解决了所有问题。
还是不完全明白为什么。
Gotcha.
WPF 4.0 application had defaulted to ".NET framework 4 Client Profile". Switching it to ".NET Framework 4" resolved all the problems.
Still don't fully understand why.