question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ambiguous types by namespace can not be resolved by using directive

See original GitHub issue

Hello community,

I am facing an issue when working with using namespace directive in PowerShell. I would like to use the Timezone implementation of Java.Util for a small project and therefore work with IKVM, what is meant to be a .net Implementation of Java providing various assembly files (.dll)

I have the following:

[System.reflection.assembly]::unsafeLoadFrom("IKVM.OpenJDK.Core.dll")
[System.reflection.assembly]::unsafeLoadFrom("IKVM.OpenJDK.Util.dll")

So far so good.

Now I am trying do to this in first line

using namespace Java.Util

Actually I am good here as well, but now I would like to do the following:

([TimeZone]::getAvailableIDs()) | { Write-Host $_}

It won’t let me do since in PowerShell I have an implicit “using System” directive in source code, causing that it will be ambiguous with System.TimeZone

It is no problem whenn calling [Java.Util.Timezone] instead but this makes the using directive being redundant.

Probably my issue is that I can’t do an alias for my namespace. In C# it would be something like using (namespace) JavaTimezone = Java.Util.Timezone

Does similar exist for PowerShell? If not I would like to add it as a feature suggestion.

P.S: In general I am quite unhappy with being the using directive not very well documented. I believe there do also things exist like “using type” and “using assembly”, but there is no documentation about it. Why is that? I’d be glad to use this stuff 😃

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lzybkrcommented, Oct 11, 2017

It would be a breaking change now, but we probably should have not have the implicit using namespace System if you have any using namespace statements.

We don’t have support for type aliases yet, but the intent was to support using type TimeZone = Java.Util.TimeZone - in fact the parser supports this today, but the semantic aspect was never implemented.

0reactions
Alextocodecommented, Oct 12, 2017

@lzybkr Thank you very much Jason. I will read carefully.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ambiguous references with the exact same namespace
Note: If I select one of the two identical namespaces in the quick fix menu, it does nothing. Note2: This happens to a...
Read more >
using directive - C# Reference
A using directive doesn't give you access to any namespaces that are nested in the namespace you specify. Namespaces come in two categories: ......
Read more >
Namespaces
Namespaces provide a method for preventing name conflicts in large projects. Symbols declared inside a namespace block are placed in a named ...
Read more >
C# 10.0 implicit global using directives
C# 10's new implicit global imports can make your code more communicative. This article shows how the magic works, and how you can...
Read more >
C# Error CS0104 – 'reference' is an ambiguous reference ...
You will receive this error when you are trying to access a class where the same name is available in multiple namespaces that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found