ODataConnectedService icon indicating copy to clipboard operation
ODataConnectedService copied to clipboard

Unable to generate T4 files due to System.IO.FileNotFoundException "Microsoft.OData.ConnectedService.dll"

Open fmcgarry opened this issue 1 year ago • 5 comments

Describe the bug

I'm trying to follow the instructions outlined here using the OData Connected Service 2022+ version of the extension in Visual Studio 2022 Enterprise with T4 files enabled.

image

Whenever I run the custom tool on the generated tt file, I receive the following error:

An exception was thrown while trying to compile the transformation code. The following Exception was thrown:
System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Microsoft.OData.ConnectedService.dll'.
File name: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Microsoft.OData.ConnectedService.dll'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Roslyn.Utilities.StandardFileSystem.OpenFile(String filePath, FileMode mode, FileAccess access, FileShare share)
   at Roslyn.Utilities.CommonCompilerFileSystemExtensions.OpenFileWithNormalizedException(ICommonCompilerFileSystem fileSystem, String filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
   at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
   at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references)
   at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation()
   at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile()
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 references, Boolean debug, SupportedLanguage language, String compilerOptions)

I've tried this in empty .NET 6-8 console projects and a .NET Standard 2.0 NuGet package project. I've also tried on a few different machines with various version of Visual Studio 2022 installed. All output the same result. Am I missing a package or some dependency that will put Microsoft.OData.ConnectedService.dll on my machine?

Version of the Project affected

OData Connected Service 2022+ v1.1.0 VisualStudio Version v17.10.5 Enterprise Microsoft.Odata.Client v7.21.3

To Reproduce

Steps to reproduce the behavior:

  1. Open Visual Studio 2022.
  2. Install the OData Connected Service 2022+ extension.
  3. Create a new empty .NET 8 console project.
  4. Follow the instructions linked here.
  5. Before clicking Finish in the OData service dialog, click the "Advanced Settings" link on the Settings page. Check "Add code templates". Then click Finish.
  6. See error.

Expected behavior

The tool succeeds in generating the OData Reference class.

Actual behavior

The Reference class file has "ErrorGeneratingOutput" and the above error is displayed in the Error List.

fmcgarry avatar Aug 05 '24 21:08 fmcgarry

@fmcgarry

Have you tried opening your project in Visual Studio 2022 with ADMIN privileges and generating the OData reference files.

WanjohiSammy avatar Aug 06 '24 09:08 WanjohiSammy

Have you tried opening your project in Visual Studio 2022 with ADMIN privileges and generating the OData reference files.

@WanjohiSammy Yes, unfortunately I see the same error.

fmcgarry avatar Aug 06 '24 13:08 fmcgarry

Thanks @fmcgarry

Please allow me to investigate this further and get back to you.

WanjohiSammy avatar Aug 06 '24 17:08 WanjohiSammy

Have the same issue. Our service description is downloaded as a local file, and is from an on-premise CRM odata endpoint.

egil avatar Aug 20 '24 17:08 egil

Hi,

Any update on this issue? I'm facing the same problem with generating the client code from the t4 template. Already tried several things like reinstalling the extension, generate from a clean project, etc..

For now I managed to use a workaround by resolving the absolute path to the dll's.

ODataT4CodeGenFilesManager.ttinclude #><#@ assembly name="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\ConnectedServices\Microsoft.VisualStudio.ConnectedServices.dll" #><#@ assembly name="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\3lvwuhuu.1vg\Microsoft.OData.ConnectedService.VS2022Plus.dll" #><#@ assembly name="System.Xml.Linq.dll" #><#@ assembly name="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\3lvwuhuu.1vg\Microsoft.OData.CodeGen.dll"

Reference.ttinclude <#@ Assembly Name="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\3lvwuhuu.1vg\Microsoft.OData.Edm.dll" #>

boosterch avatar Jan 07 '25 09:01 boosterch